public static void Search_SearchTweet() { // IF YOU DO NOT RECEIVE ANY TWEET, CHANGE THE PARAMETERS! var searchParameter = Search.CreateTweetSearchParameter("obama"); searchParameter.SetGeoCode(Geo.GenerateCoordinates(-122.398720, 37.781157), 1, DistanceMeasure.Miles); searchParameter.Lang = Language.English; searchParameter.SearchType = SearchResultType.Popular; searchParameter.MaximumNumberOfResults = 100; searchParameter.Since = new DateTime(2013, 12, 1); searchParameter.Until = new DateTime(2013, 12, 11); searchParameter.SinceId = 399616835892781056; searchParameter.MaxId = 405001488843284480; searchParameter.TweetSearchType = TweetSearchType.OriginalTweetsOnly; searchParameter.Filters = TweetSearchFilters.Videos; var tweets = Search.SearchTweets(searchParameter); // if auth is not successful if (tweets == null) { Console.WriteLine(ExceptionHandler.GetLastException().TwitterDescription); return; } StringBuilder builder = new StringBuilder(); //tweets.ForEach(t => builder.Append(t.Text)); PropertyInfo [] props = typeof(ITweet).GetProperties(); foreach (var tweet in tweets) { builder.Append(tweet.CreatedAt); foreach (var prop in props) { if (prop.CanRead) { builder.Append(prop.GetValue(tweet, null)).Append("\t"); } } builder.Append("\n"); } System.IO.StreamWriter file = new StreamWriter("a.txt"); file.Write(builder.ToString()); file.Close(); }
/// <summary> /// Populate a tweet from information retrieved from twitter /// </summary> /// <param name="dTweet">Object containing Tweet information</param> /// <param name="cleanString">Does the string needs to be cleanup when retrieved</param> protected virtual void Populate(Dictionary <String, object> dTweet, bool cleanString) { if (dTweet.GetProp("id") != null) { CreatedAt = DateTime.ParseExact(dTweet.GetProp("created_at") as string, "ddd MMM dd HH:mm:ss zzzz yyyy", CultureInfo.InvariantCulture); Id = Convert.ToInt64(dTweet.GetProp("id_str")); IdValue = Convert.ToInt64(dTweet.GetProp("id")); IdStr = dTweet.GetProp("id_str") as string; Text = dTweet.GetProp("text") as string; Source = dTweet.GetProp("source ") as string; Truncated = dTweet.GetProp("truncated") as bool?; InReplyToStatusId = dTweet.GetProp("in_reply_to_status_id") as int?; InReplyToStatusIdStr = dTweet.GetProp("in_reply_to_status_id_str") as string; InReplyToUserId = dTweet.GetProp("in_reply_to_user_id") as int?; InReplyToUserIdStr = dTweet.GetProp("in_reply_to_user_id_str") as string; InReplyToScreenName = dTweet.GetProp("in_reply_to_screen_name") as string; Creator = User.Create(dTweet.GetProp("user")); if (_shareTokenWithChild) { Creator.ObjectToken = _token; } Location = Geo.Create(dTweet.GetProp("geo")); if (Location != null) { LocationCoordinates = Location.GeoCoordinates; } // Create Place _place = dTweet.GetProp("place") as string; // Create Contributors var contributors = dTweet.GetProp("contributors"); RetweetCount = dTweet.GetProp("retweet_count") as int?; if (dTweet.ContainsKey("entities")) { Entities = new TweetEntities(dTweet["entities"] as Dictionary <String, object>); } Favourited = dTweet.GetProp("favorited") as bool?; Retweeted = dTweet.GetProp("retweeted") as bool?; PossiblySensitive = dTweet.GetProp("possibly_sensitive") as bool?; if (dTweet.ContainsKey("retweeted_status")) { var retweet = dTweet.GetProp("retweeted_status") as Dictionary <string, object>; if (retweet != null) { Retweeting = new Tweet(retweet); } } if (cleanString) { Text = Text.CleanString(); } _isTweetPublished = true; } }