Exemplo n.º 1
0
        /// <summary>
        /// クエリを指定してツイートを検索
        /// </summary>
        /// <param name="query">検索クエリ.</param>
        /// <param name="consumerKey">コンシューマキー</param>
        /// <param name="consumerSecret">コンシューマシークレット</param>
        /// <param name="response">Twitter.API.GetAccessTokenで取得したアクセストークン</param>
        /// <param name="callback">検索結果を受け取るコールバック</param>
        /// <example>
        ///
        /// /*使用例*/
        ///
        /// Twitter.AccessTokenResponse m_AccessTokenResponse; // 事前にTwitter.API.GetAccessTokenでアクセストークンを取得しておく
        ///
        /// void SerchByHashTag()
        /// {
        ///     // ハッシュタグ "#Unity" で検索(終了するとOnSearchTweetsResponseが実行される)
        ///     StartCoroutine(Twitter.API.SearchTweets("#Unity", "CONSUMER_KEY", "CONSUMER_SECRET", m_AccessTokenResponse, OnSearchTweetsResponse));
        /// }
        ///
        /// void OnSearchTweetsResponse(bool success, string response)
        /// {
        ///     // responseに検索結果のJSON文字列が入ってくるので解析して各ツイートのテキストを得る
        /// }
        ///
        /// </example>
        public static IEnumerator SearchTweets(string query, string consumerKey, string consumerSecret, AccessTokenResponse response, CommonCallback callback)
        {
            var parameters = new Dictionary <string, string>();

            parameters["q"] = query;

            return(CommonRequest("search/tweets", Method.GET, parameters, consumerKey, consumerSecret, response, callback));
        }
Exemplo n.º 2
0
        private static IEnumerator CommonRequest(string api, Method method, Dictionary <string, string> parameters, string consumerKey, string consumerSecret, AccessTokenResponse response, CommonCallback callback)
        {
            string baseURL = string.Format(ApiBaseURL, api);
            string url     = baseURL;

            byte[] data = null;

            if (parameters == null)
            {
                parameters = new Dictionary <string, string>();
            }

            if (method == Method.GET)
            {
                url = BuildURL(url, parameters);
            }

            if (method == Method.POST)
            {
                WWWForm form = new WWWForm();
                foreach (var pair in parameters)
                {
                    form.AddField(pair.Key, pair.Value);
                }
                data = form.data;
            }

            //var headers = new Hashtable();
            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers["Authorization"] = GetHeaderWithAccessToken(method.ToString(), url, consumerKey, consumerSecret, response, parameters);

            WWW web = new WWW(url, data, headers);

            yield return(web);

            if (!string.IsNullOrEmpty(web.error))
            {
                Debug.Log(string.Format("{0} failed. {1}\n{2}", api, web.error, web.text));
                callback(false, web.error);
            }
            else
            {
                string error = Regex.Match(web.text, @"<error>([^&]+)</error>").Groups[1].Value;

                if (!string.IsNullOrEmpty(error))
                {
                    Debug.Log(string.Format("{0} failed. {1}\n{2}", api, web.error, web.text));
                    callback(false, web.text);
                }
                else
                {
                    callback(true, web.text);
                }
            }
        }
Exemplo n.º 3
0
 public static void SetRenderCallBack(CommonCallback _render)
 {
     render += _render;
 }