コード例 #1
0
ファイル: twitterRequest.cs プロジェクト: radi-bow/HoloTweet
        private static IEnumerator SendRequest(UnityWebRequest request, SortedDictionary<string, string> parameters, string method, string requestURL, TwitterCallback callback)
        {
            request.SetRequestHeader("Authorization", Oauth.GenerateHeaderWithAccessToken(parameters, method, requestURL));
            #if UNITY_2017_1
                    yield return request.Send();
            #endif
            #if UNITY_2017_2_OR_NEWER
                    yield return request.SendWebRequest();
            #endif

            if (request.isNetworkError)
            {
                callback(false, JsonHelper.ArrayToObject(request.error));
            }
            else
            {
                if (request.responseCode == 200 || request.responseCode == 201)
                {
                    callback(true, JsonHelper.ArrayToObject(request.downloadHandler.text));
                }
                else
                {
                    Debug.Log(request.responseCode);
                    callback(false, JsonHelper.ArrayToObject(request.downloadHandler.text));
                }
            }
        }
コード例 #2
0
        public static IEnumerator GenerateAccessToken(string pin, TwitterAuthenticationCallback callback)
        {
            string url = "https://api.twitter.com/oauth/access_token";

            SortedDictionary <string, string> p = new SortedDictionary <string, string>();

            p.Add("oauth_verifier", pin);

            WWWForm form = new WWWForm();

            form.AddField("oauth_verifier", pin);

            UnityWebRequest request = UnityWebRequest.Post(url, form);

            request.SetRequestHeader("Authorization", Oauth.GenerateHeaderWithAccessToken(p, "POST", url));

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

            if (request.isNetworkError)
            {
                callback(false);
            }
            else
            {
                if (request.responseCode == 200 || request.responseCode == 201)
                {
                    string[] arr = request.downloadHandler.text.Split("&"[0]);
                    Dictionary <string, string> d = new Dictionary <string, string>();
                    foreach (string s in arr)
                    {
                        string k = s.Split("="[0])[0];
                        string v = s.Split("="[0])[1];
                        d[k] = v;
                    }
                    Oauth.accessToken       = d["oauth_token"];
                    Oauth.accessTokenSecret = d["oauth_token_secret"];
                    screenName = d["screen_name"];
                    callback(true);
                }
                else
                {
                    callback(false);
                }
            }
        }
コード例 #3
0
ファイル: TwitterStream.cs プロジェクト: sarafrandsen/Twity
        public IEnumerator On(Dictionary <string, string> APIParams, TwitterStreamCallback callback)
        {
            SortedDictionary <string, string> parameters = Helper.ConvertToSortedDictionary(APIParams);

            WWWForm form = new WWWForm();

            foreach (KeyValuePair <string, string> parameter in APIParams)
            {
                form.AddField(parameter.Key, parameter.Value);
            }

            request = UnityWebRequest.Post(REQUEST_URL, form);
            request.SetRequestHeader("ContentType", "application/x-www-form-urlencoded");
            request.SetRequestHeader("Authorization", Oauth.GenerateHeaderWithAccessToken(parameters, "POST", REQUEST_URL));
            request.downloadHandler = new StreamingDownloadHandler(callback);
            yield return(request.SendWebRequest());
        }