public string TwitterTweetSearchWithGeoLocation(string q, string geoCode) { if (q.Contains("#")) { q = Uri.EscapeUriString(q); } try { string url = string.Empty; if (!string.IsNullOrEmpty(geoCode)) { url = q.Trim() + "&geocode=" + geoCode + "&count=20&result_type=recent"; } else { url = q.Trim() + "&count=20&result_type=recent"; } string ret = string.Empty; JArray output = new JArray(); SortedDictionary <string, string> requestParameters = new SortedDictionary <string, string>(); var oauth_url = "https://api.twitter.com/1.1/search/tweets.json?q=" + url; var headerFormat = "Bearer {0}"; var authHeader = string.Format(headerFormat, "AAAAAAAAAAAAAAAAAAAAAOZyVwAAAAAAgI0VcykgJ600le2YdR4uhKgjaMs%3D0MYOt4LpwCTAIi46HYWa85ZcJ81qi0D9sh8avr1Zwf7BDzgdHT"); var postBody = requestParameters.ToWebString(); ServicePointManager.Expect100Continue = false; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(oauth_url + "?" + requestParameters.ToWebString()); request.Headers.Add("Authorization", authHeader); request.Method = "GET"; request.Headers.Add("Accept-Encoding", "gzip"); HttpWebResponse response = request.GetResponse() as HttpWebResponse; Stream responseStream = new GZipStream(response.GetResponseStream(), CompressionMode.Decompress); using (var reader = new StreamReader(responseStream)) { var objText = reader.ReadToEnd(); output = JArray.Parse(JObject.Parse(objText)["statuses"].ToString()); } Domain.Socioboard.Helper.Discovery _Discovery; List <Domain.Socioboard.Helper.Discovery> lstDiscovery = new List <Domain.Socioboard.Helper.Discovery>(); try { foreach (var item in output) { try { _Discovery = new Domain.Socioboard.Helper.Discovery(); _Discovery.text = item["text"].ToString(); _Discovery.created_at = Utility.ParseTwitterTime(item["created_at"].ToString()); _Discovery.tweet_id = item["id_str"].ToString(); _Discovery.twitter_id = item["user"]["id_str"].ToString(); _Discovery.profile_image_url = item["user"]["profile_image_url"].ToString(); _Discovery.screan_name = item["user"]["screen_name"].ToString(); _Discovery.name = item["user"]["name"].ToString(); _Discovery.description = item["user"]["description"].ToString(); _Discovery.followers_count = item["user"]["followers_count"].ToString(); _Discovery.friends_count = item["user"]["friends_count"].ToString(); lstDiscovery.Add(_Discovery); } catch { } } } catch { } return(new JavaScriptSerializer().Serialize(lstDiscovery)); } catch (Exception ex) { return(new JavaScriptSerializer().Serialize(new List <Domain.Socioboard.Helper.Discovery>())); } }
public string TwitterTweetSearchWithGeoLocation(string q, string geoCode) { if (q.Contains("#")) { q = Uri.EscapeUriString(q); } try { string url = string.Empty; if (!string.IsNullOrEmpty(geoCode)) { url = q.Trim() + "&geocode=" + geoCode + "&count=20&result_type=recent"; } else { url = q.Trim() + "&count=20&result_type=recent"; } string ret = string.Empty; JArray output = new JArray(); SortedDictionary<string, string> requestParameters = new SortedDictionary<string, string>(); var oauth_url = "https://api.twitter.com/1.1/search/tweets.json?q=" + url; var headerFormat = "Bearer {0}"; var authHeader = string.Format(headerFormat, "AAAAAAAAAAAAAAAAAAAAAOZyVwAAAAAAgI0VcykgJ600le2YdR4uhKgjaMs%3D0MYOt4LpwCTAIi46HYWa85ZcJ81qi0D9sh8avr1Zwf7BDzgdHT"); var postBody = requestParameters.ToWebString(); ServicePointManager.Expect100Continue = false; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(oauth_url + "?" + requestParameters.ToWebString()); request.Headers.Add("Authorization", authHeader); request.Method = "GET"; request.Headers.Add("Accept-Encoding", "gzip"); HttpWebResponse response = request.GetResponse() as HttpWebResponse; Stream responseStream = new GZipStream(response.GetResponseStream(), CompressionMode.Decompress); using (var reader = new StreamReader(responseStream)) { var objText = reader.ReadToEnd(); output = JArray.Parse(JObject.Parse(objText)["statuses"].ToString()); } Domain.Socioboard.Helper.Discovery _Discovery; List<Domain.Socioboard.Helper.Discovery> lstDiscovery = new List<Domain.Socioboard.Helper.Discovery>(); try { foreach (var item in output) { try { _Discovery = new Domain.Socioboard.Helper.Discovery(); _Discovery.text = item["text"].ToString(); _Discovery.created_at = Utility.ParseTwitterTime(item["created_at"].ToString()); _Discovery.tweet_id = item["id_str"].ToString(); _Discovery.twitter_id = item["user"]["id_str"].ToString(); _Discovery.profile_image_url = item["user"]["profile_image_url"].ToString(); _Discovery.screan_name = item["user"]["screen_name"].ToString(); _Discovery.name = item["user"]["name"].ToString(); _Discovery.description = item["user"]["description"].ToString(); _Discovery.followers_count = item["user"]["followers_count"].ToString(); _Discovery.friends_count = item["user"]["friends_count"].ToString(); lstDiscovery.Add(_Discovery); } catch { } } } catch { } return new JavaScriptSerializer().Serialize(lstDiscovery); } catch (Exception ex) { return new JavaScriptSerializer().Serialize(new List<Domain.Socioboard.Helper.Discovery>()); } }