UnityでTwitterの機能使いたい

Unityで簡単にTwitterの機能使えないかな

そんなことを思って探してみましたが、
もちろんライブラリ作ってくれてる方はいるんですね。
本当にすごい!!

qiita.com

Twityを使ってみたところ少々勉強になったことがあったんで投稿。

環境

  • Unity2017.1.2f1 (これが問題になりました)
  • VisualStudio2017 Version 15.5.5

試す

ダウンロードし、まるまるUnityのアセットに入れる。
コンパイルエラー!!!!

Assets/Twity/scripts/twitterRequest.cs(116,34): error CS1061: Type `UnityEngine.Networking.UnityWebRequest' does not contain a definition for `SendWebRequest' and no extension method `SendWebRequest' of type `UnityEngine.Networking.UnityWebRequest' could be found. Are you missing an assembly reference?

どうやら定義されていないとのこと。
定義まで掘って探してみても、確かにない。
リファレンスを調べてみました

Unity - Scripting API: Networking.UnityWebRequest.SendWebRequest

なぜないんだ?って思って、VisualStudioで定義を見てみると、

// 概要:
//     Begin communicating with the remote server.
//
// 戻り値:
//     An AsyncOperation indicating the progress/completion state of the UnityWebRequest.
//     Yield this object to wait until the UnityWebRequest is done.
public AsyncOperation Send();

怪しいものを見つけてしまいました。
調べてみると出ます

docs.unity3d.com

このURL内の 540current に変更します。
currentに変更すると今のバージョンでのリファレンスが出るのでよく使ってます。
Method group is Obsolete
google翻訳様曰く、廃れたそうです。。
悲しいですね。

Unityは新しいバージョンを出すときに、以前のバージョンのメソッド名など
変更してサポートしないことが多いそうです。

自分のUnityは2017.1でちょうど変更前だったみたいですね。

#if UNITY_2017_2
            yield return request.SendWebRequest();
#endif
#if UNITY_2017_1
            yield return request.Send();
#endif

該当箇所をif文で回避。

さらに、search/tweetsを試しました

SearchTweetsResponse Response = JsonUtility.FromJson<SearchTweetsResponse>(response);

            foreach(var status in Response.statuses)
            {
                // ツイートしたユーザー名が取れます
                Debug.Log(status.user.name);
                // ツイートされたテキストが取れます
                Debug.Log(status.text);
            }

TwitterAPIと良く読み合せればいろんなことができそう!
しばらく遊んでみます!