public void In_Search(string query) { var searchOptions = new SearchOptions { ResultType = SearchOptionsResultType.Recent }; var results = Twitterizer.TwitterSearch.Search(query, searchOptions); Out_Result(results); }
public static void Search() { SearchOptions options = new SearchOptions(); options.NumberPerPage = 19; var searchResponse = TwitterSearch.Search("twitter", options); Assert.IsNotNull(searchResponse); Assert.That(searchResponse.Result == RequestResult.Success, searchResponse.ErrorMessage); Assert.IsNotNull(searchResponse.ResponseObject); Assert.That(searchResponse.ResponseObject.Count == 19); var request = Twitterizer.TwitterSearch.Search("twitter"); Assert.IsNotNull(request); Assert.That(request.Result == RequestResult.Success, request.ErrorMessage); Assert.IsNotNull(request.ResponseObject); //Assert.Greater(request.ResponseObject.MaxId, 0); //Assert.Greater(request.ResponseObject.CompletedIn, 0); //Assert.IsNotNullOrEmpty(request.ResponseObject.MaxIdStr); //Assert.IsNotNullOrEmpty(request.ResponseObject.NextPage); //Assert.Greater(request.ResponseObject.Page, 0); //Assert.AreEqual("twitter", request.ResponseObject.Query); //Assert.IsNotNullOrEmpty(request.ResponseObject.RefreshUrl); }
/// <summary> /// Searches Twitter with the the specified query. /// </summary> /// <param name="query">The query.</param> /// <param name="tokens">The tokens. Leave null for unauthenticated request.</param> /// <param name="options">The options. Leave null for defaults.</param> /// <returns> /// A <see cref="TwitterSearchResultCollection"/> instance. /// </returns> public static async Task<TwitterResponse<TwitterSearchResultCollection>> SearchAsync(string query, OAuthTokens tokens = null, SearchOptions options = null) { if (options == null) options = new SearchOptions(); return await Core.CommandPerformer.PerformAction(new Twitterizer.Commands.SearchCommand(tokens, query, options)); }
/// <summary> /// Searches Twitter with the the specified query. /// </summary> /// <param name="query">The query.</param> /// <param name="options">The options.</param> /// <param name="timeout">The timeout.</param> /// <param name="function">The function.</param> /// <returns></returns> public static IAsyncResult Search(string query, SearchOptions options, TimeSpan timeout, Action<TwitterAsyncResponse<TwitterSearchResultCollection>> function) { #if !SILVERLIGHT Func<string, SearchOptions, TwitterResponse<TwitterSearchResultCollection>> methodToCall = TwitterSearch.Search; return methodToCall.BeginInvoke( query, options, result => { result.AsyncWaitHandle.WaitOne(timeout); try { function(methodToCall.EndInvoke(result).ToAsyncResponse()); } catch (Exception ex) { function(new TwitterAsyncResponse<TwitterSearchResultCollection>() { Result = RequestResult.Unknown, ExceptionThrown = ex }); } }, null); #else ThreadPool.QueueUserWorkItem((x) => { function(TwitterSearch.Search(query, options).ToAsyncResponse<TwitterSearchResultCollection>()); }); return null; #endif }
public string[] GetHashTweet() { string[] values = new string[]{}; if (this.Options == null || this.Options.GetParameter("hashtag") == null) { return values; } Parameter hashtagParameter = this.Options.GetParameter("hashtag"); SearchOptions searchOptions = new SearchOptions { ResultType = SearchOptionsResultType.Recent, IncludeEntities = false, SinceId = lastHashtagId }; TwitterResponse<TwitterSearchResultCollection> response = TwitterSearch.Search(hashtagParameter.Value, searchOptions); if (response.Result == RequestResult.Success) { TwitterSearchResultCollection results = response.ResponseObject; List<TwitterSearchResult> listResults = new List<TwitterSearchResult>(results); this.lastHashtagId = listResults.Min(t => t.Id); TwitterSearchResult searchResult = listResults.Find(t => t.Id == this.lastHashtagId); values = new string[] { searchResult.CreatedDate.ToShortDateString(), searchResult.FromUserDisplayName, searchResult.Text }; } return values; }
public string GetResponse(RepositoryOptions options) { var opt = new SearchOptions(); opt.MaxId = maxRequest; opt.SinceId = sinceId; opt.Count = options.apiCallProperties.Count; var response = TwitterSearch.Search(GenerateAuthentication(), options.Query, opt); return response.Content; }
public static void SearchLocal() { SearchOptions options = new SearchOptions(); options.GeoCode = "30.4413,-84.2809,20mi"; TwitterResponse<TwitterSearchResultCollection> searchResponse = TwitterSearch.Search("", options); Assert.IsNotNull(searchResponse); Assert.That(searchResponse.Result == RequestResult.Success, searchResponse.ErrorMessage); Assert.IsNotNull(searchResponse.ResponseObject); }
/// <summary> /// Searches Twitter with the the specified query. /// </summary> /// <param name="tokens">The tokens.</param> /// <param name="query">The query.</param> /// <param name="options">The options.</param> /// <returns> /// A <see cref="TwitterSearchResultCollection"/> instance. /// </returns> public static TwitterResponse<TwitterSearchResultCollection> Search(OAuthTokens tokens, string query, SearchOptions options) { if (options == null) options = new SearchOptions(); Commands.SearchCommand command = new Twitterizer.Commands.SearchCommand(tokens, query, options); TwitterResponse<TwitterSearchResultCollection> results = Core.CommandPerformer<TwitterSearchResultCollection>.PerformAction(command); return results; }
public JsonResult Old_Index() { OAuthTokens tokens = new OAuthTokens(); tokens.AccessToken = "948267493-vHd6rvvYXPC8FbRG2hawcCmi7P9kaUpCRUPibQhq"; tokens.AccessTokenSecret = "tSHBIwINVxcTSW2E35gYU6PpZOSCVGMcMdq2O9vnBS8"; tokens.ConsumerKey = "j9wouFSIcK1Wjfjy5iKpyg"; tokens.ConsumerSecret = "GJGaaB5TuYRyhcSYzLQvHNBrZGXTvpFw0eE6vsoswY8"; var options = new SearchOptions() { PageNumber = 1, NumberPerPage = 5 }; TwitterResponse<TwitterSearchResultCollection> searchResult = TwitterSearch.Search("goodtimesushi", options); return Json(searchResult.ResponseObject, JsonRequestBehavior.AllowGet); }
public void Search() { SearchOptions options = new SearchOptions(); options.NumberPerPage = 19; TwitterResponse<TwitterSearchResultCollection> searchResponse = TwitterSearch.Search("twitter", options); Assert.IsNotNull(searchResponse, "searchResponse is null"); Assert.IsTrue(searchResponse.Result == RequestResult.Success, searchResponse.ErrorMessage); Assert.IsNotNull(searchResponse.ResponseObject, searchResponse.ErrorMessage); Assert.IsTrue(searchResponse.ResponseObject.Count == 19); var request = Twitterizer.TwitterSearch.Search("twitter"); Assert.IsNotNull(request, "request is null"); Assert.IsTrue(request.Result == RequestResult.Success, request.ErrorMessage); Assert.IsNotNull(request.ResponseObject, request.ErrorMessage); }
/// <summary> /// Searches Twitter with the the specified query. /// </summary> /// <param name="query">The query.</param> /// <param name="options">The options.</param> /// <param name="timeout">The timeout.</param> /// <param name="function">The function.</param> /// <returns></returns> public static IAsyncResult Search(string query, SearchOptions options, TimeSpan timeout, Action<TwitterAsyncResponse<TwitterSearchResultCollection>> function) { Func<string, SearchOptions, TwitterResponse<TwitterSearchResultCollection>> methodToCall = TwitterSearch.Search; return methodToCall.BeginInvoke( query, options, result => { result.AsyncWaitHandle.WaitOne(timeout); try { function(methodToCall.EndInvoke(result).ToAsyncResponse()); } catch (Exception ex) { function(new TwitterAsyncResponse<TwitterSearchResultCollection>() { Result = RequestResult.Unknown, ExceptionThrown = ex }); } }, null); }
/// <summary> /// Returns search results. Returns results from cache if available, otherwise fetches results from Twitter API. /// </summary> private TwitterSearchResultCollection GetTwitterResults(string query, int twitterPageNumber, bool newSearch) { // Check cache for data if (!newSearch && twitterPageNumber == _localCache.PageNumber && _localCache.PageResults != null) { return _localCache.PageResults; } // Build search parameters SearchOptions searchOptions = new SearchOptions(); searchOptions.NumberPerPage = TWITTER_PAGE_SIZE; searchOptions.PageNumber = twitterPageNumber; if (!newSearch && _localCache.MaxId.HasValue) { searchOptions.MaxId = _localCache.MaxId.Value; } // Execute search TwitterResponse<TwitterSearchResultCollection> twitterResponse = _searchService.Search(query, searchOptions); // Throw errors, connection failures back to the UI for proper handling if (twitterResponse.Result != RequestResult.Success) { throw new TwitterSearchException(twitterResponse.Result, query); } // Store the MaxId for later to maintain page consistency _localCache.MaxId = twitterResponse.ResponseObject.MaxId; // Cache results for future requests _localCache.PageResults = twitterResponse.ResponseObject; _localCache.PageNumber = searchOptions.PageNumber; return twitterResponse.ResponseObject; }
static void Main(string[] args) { // publish arrivals var arrivals = GetArrivals(); foreach (var a in arrivals) { var arrivaltime = DateTime.Parse(a.date + " " + a.scheduled_arrival_time); if ((arrivaltime < DateTime.Now) && arrivaltime > DateTime.Now.AddMinutes(-int.Parse(System.Configuration.ConfigurationManager.AppSettings["SchedulePeriod"]))) { var greeting = ""; if ((arrivaltime.Hour > new DateTime(2010, 10, 9, 9,0,0).Hour && arrivaltime.Hour < new DateTime(2010, 10, 12,12,0,0).Hour)) { greeting = "Ay up!"; } else if ((arrivaltime.Hour > new DateTime(2010, 10, 13,13,0,0).Hour && arrivaltime.Hour < new DateTime(2010, 10, 16,16,0,0).Hour)) { greeting = "'Ows ta bin?"; } else if ((arrivaltime.Hour > new DateTime(2010, 10, 19,19,0,0).Hour && arrivaltime.Hour < new DateTime(2010, 10, 22,22,0,0).Hour)) { greeting = "Now then."; } Tweet(string.Format("{2} Flight {0} from {1} has landed. #robinhoodairport", a.flight_number, a.from, greeting)); } } //publish departures var departures = GetDepartures(); foreach (var d in departures) { var arrivaltime = DateTime.Parse(d.date + " " + d.scheduled_departure_time); if ((arrivaltime < DateTime.Now) && arrivaltime > DateTime.Now.AddMinutes(-int.Parse(System.Configuration.ConfigurationManager.AppSettings["SchedulePeriod"]))) { var greeting = ""; if ((arrivaltime.Hour > new DateTime(2010, 10, 13, 9, 0, 0).Hour && arrivaltime.Hour < new DateTime(2010, 10, 12, 12,0,0).Hour)) { greeting = "Now then."; } else if((arrivaltime.Hour > new DateTime(2010, 10, 13, 13, 0, 0).Hour && arrivaltime.Hour < new DateTime(2010, 10, 16, 16,0,0).Hour)) { greeting = "Ay up!"; } else if ((arrivaltime.Hour > new DateTime(2010, 10, 19, 19,0,0).Hour && arrivaltime.Hour < new DateTime(2010, 10, 22, 22,0,0).Hour)) { greeting = "'Ows ta bin?"; } Tweet(string.Format("{2} Flight {0} to {1} has taken off. #robinhoodairport", d.flight_number, d.destination, greeting)); } } //respond to tweets OAuthTokens tokens = new OAuthTokens(); tokens.AccessToken = System.Configuration.ConfigurationManager.AppSettings["AccessToken"]; tokens.AccessTokenSecret = System.Configuration.ConfigurationManager.AppSettings["AccessTokenSecret"]; tokens.ConsumerKey = System.Configuration.ConfigurationManager.AppSettings["ConsumerKey"]; tokens.ConsumerSecret = System.Configuration.ConfigurationManager.AppSettings["ConsumerSecret"]; string query = "@robin_hood_air"; SearchOptions options = new SearchOptions() { PageNumber = 1, NumberPerPage = 50 }; TwitterResponse<TwitterSearchResultCollection> searchResult = TwitterSearch.Search(query, options); foreach (var tweet in searchResult.ResponseObject) { RespondToTweet(tweet); } }
/// <summary> /// Searches Twitter with the the specified query. /// </summary> /// <param name="tokens">The tokens.</param> /// <param name="query">The query.</param> /// <param name="options">The options.</param> /// <returns> /// A <see cref="TwitterSearchResultCollection"/> instance. /// </returns> public static TwitterResponse <TwitterSearchResultCollection> Search(OAuthTokens tokens, string query, SearchOptions options) { if (options == null) { options = new SearchOptions(); } Commands.SearchCommand command = new Twitterizer.Commands.SearchCommand(tokens, query, options); TwitterResponse <TwitterSearchResultCollection> results = Core.CommandPerformer.PerformAction(command); return(results); }
internal List<string> searchTweets(String keyword) { List<string> foundTweets = new List<string>(); string query = "#Twitterizer"; int pageNumber = 1; SearchOptions options = new SearchOptions() { PageNumber = pageNumber, NumberPerPage = 2 }; TwitterResponse<TwitterSearchResultCollection> searchResult = TwitterSearch.Search(query, options); while (searchResult.Result == RequestResult.Success && pageNumber < 5) { Console.WriteLine("==== PAGE {0} ====", pageNumber); Console.WriteLine(); foreach (var tweet in searchResult.ResponseObject) { Console.WriteLine("[{0}] {1,-10}: {2}", tweet.CreatedDate, tweet.FromUserScreenName, tweet.Text); } pageNumber++; options.PageNumber = pageNumber; searchResult = TwitterSearch.Search(query, options); Console.WriteLine(); } return foundTweets; }
public ActionResult Search(string queryString) { try { // recoord the search results in our DB Contect using (var db = new TwitterMyMVC.Web.Models.TwitterMyMVCContext()) { if (!String.IsNullOrWhiteSpace(queryString)) { // For simplicity, only get top 5 SearchOptions options = new SearchOptions() { PageNumber = 1, NumberPerPage = 5 }; var searchResponse = TwitterSearch.Search(queryString, options); if (searchResponse.Result == RequestResult.Success) { // check if this search already exists in our DB Models.Search myMVCSearch = (from s in db.Searches where s.QueryString == queryString select s).FirstOrDefault(); if (myMVCSearch == null) { myMVCSearch = new TwitterMyMVC.Web.Models.Search() { QueryString = queryString }; db.Searches.Add(myMVCSearch); } foreach (var tweet in searchResponse.ResponseObject) { // check if this tweet has already been recorded var myMVCTweet = (from t in db.Tweets where t.TwitterId == tweet.Id select t).FirstOrDefault(); if (myMVCTweet == null) { var myMVCTweeter = (from tr in db.Tweeters where tr.TwitterId == tweet.FromUserId select tr).FirstOrDefault(); if (myMVCTweeter == null) { myMVCTweeter = new Models.Tweeter() { ProfileImageLocation = tweet.ProfileImageLocation, TwitterId = tweet.FromUserId, ScreenName = tweet.FromUserScreenName }; db.Tweeters.Add(myMVCTweeter); } myMVCTweet = new TwitterMyMVC.Web.Models.Tweet() { Text = tweet.Text, TwitterId = tweet.Id, Tweeter = myMVCTweeter, }; db.Tweets.Add(myMVCTweet); } // add this tweet to the search results if it's not already there if (!myMVCSearch.SearchResults.Any(sr => myMVCTweet.TweetId > 0 && sr.Tweet.TweetId == myMVCTweet.TweetId)) { db.SearchResults.Add(new Models.SearchResult() { Tweet = myMVCTweet, Search = myMVCSearch }); } // forced to save changes in loop because, items are getting added twice. // I'm sure there's a better way, just getting tired... db.SaveChanges(); } ViewBag.twitterSearchResults = db.SearchResults .Include("Tweet") .Include("Tweet.Tweeter") .Where(sr => sr.SearchId == myMVCSearch.SearchId).ToList(); } else { //LogErrorDetails(serachResponse.RequestUrl, searchResponse.ErrorMessage, searchResponse.Content); //DisplayErrorMessageToUser(searchResponse.ErrorMessage); } } // get the top 5 tweeters // a little rough... but started running out of time ViewBag.topTweeters = (from tweet in db.Tweets group tweet by new { TweeterId = tweet.TweeterId, ProfileImageLocation = tweet.Tweeter.ProfileImageLocation, ScreenName = tweet.Tweeter.ScreenName, } into Tweet select new Models.TopTweeter() { TweeterId = Tweet.Key.TweeterId, ProfileImageLocation = Tweet.Key.ProfileImageLocation, ScreenName = Tweet.Key.ScreenName, NumTweets = Tweet.Count() }).OrderByDescending(x => x.NumTweets).Take(5).ToList(); return View(); } } catch (Exception ex) { return View("Error"); //LogException(ex); //DisplayErrorMessageToUser("There was a problem performing the Twitter Search."); } }
/// <summary> /// Searches Twitter with the the specified query. /// </summary> /// <param name="tokens">The tokens.</param> /// <param name="query">The query.</param> /// <param name="options">The options.</param> /// <param name="timeout">The timeout.</param> /// <param name="function">The function.</param> /// <returns></returns> public static IAsyncResult Search(OAuthTokens tokens, string query, SearchOptions options, TimeSpan timeout, Action<TwitterAsyncResponse<TwitterSearchResultCollection>> function) { return AsyncUtility.ExecuteAsyncMethod(tokens, query, options, timeout, TwitterSearch.Search, function); }
private static void ProcessTwitter(Account a) { string query = "@" + a.Name; int pageNumber = 0; var id = BLL.Accounts.GetLastPostID(a.ID); SearchOptions options = new SearchOptions() { PageNumber = pageNumber, NumberPerPage = 20, }; if (id.HasValue) options.SinceId = id.Value; else options.SinceDate = DateTime.Now.AddDays(-1); TwitterResponse<TwitterSearchResultCollection> searchResult = TwitterSearch.Search(query, options); //while (searchResult.Result == RequestResult.Success) //{ foreach (var tweet in searchResult.ResponseObject) { if (BLL.Posts.Get().Where(Posts.Columns.ForeignID, Actions.Equal, tweet.Id.ToString()).SelectOne() != null) return; var post = new Post { AccountID = a.ID, ForeignID = tweet.Id.ToString(), Text = tweet.Text, Type = (int)AccountType.Twitter, FromUserName = tweet.FromUserScreenName }; ProcessPost(post); post.Insert(); } Console.WriteLine(); //} Console.Write("finished Account " + a.Name); }
public List<string> getCurrentTweetsForHash(string hash) { List<string> tweets = new List<string>(); SearchOptions options = new SearchOptions() { PageNumber = 1, NumberPerPage = 10 }; TwitterResponse<TwitterSearchResultCollection> result = TwitterSearch.Search(hash, options); foreach (TwitterSearchResult tweet in result.ResponseObject) { tweets.Add(this.getTweetFormated(tweet)); } return tweets; }
/// <summary> /// Searches Twitter with the the specified query. /// </summary> /// <param name="query">The query.</param> /// <param name="options">The options.</param> /// <returns> /// A <see cref="TwitterSearchResultCollection"/> instance. /// </returns> public static TwitterResponse<TwitterSearchResultCollection> Search(string query, SearchOptions options) { return Search(null, query, options); }
public TwitterResponse<TwitterSearchResultCollection> Search(string query, SearchOptions searchOptions) { return TwitterSearch.Search(query, searchOptions); }
/// <summary> /// Searches Twitter with the the specified query. /// </summary> /// <param name="query">The query.</param> /// <param name="options">The options.</param> /// <returns> /// A <see cref="TwitterSearchResultCollection"/> instance. /// </returns> public static TwitterResponse <TwitterSearchResultCollection> Search(string query, SearchOptions options) { return(Search(null, query, options)); }