/// <summary> /// Gets tweets posted by specified user /// </summary> /// <param name="messageCount">Message count</param> /// <returns>Message list</returns> public List <Message> GetUserTweets(decimal?userID, string screenName, int messageCount) { try { Twitterizer.OAuthTokens tokens = GetOAuthTokens(); Twitterizer.UserTimelineOptions options = new Twitterizer.UserTimelineOptions(); options.ScreenName = screenName; if (userID.HasValue) { options.UserId = userID.Value; } options.IncludeRetweets = true; options.Count = messageCount; TwitterResponse <TwitterStatusCollection> statusResponse = TwitterTimeline.UserTimeline(tokens, options); if (statusResponse.Result == RequestResult.Success) { return(MapMessage(statusResponse.ResponseObject)); } else { throw CreateException(statusResponse.Result, statusResponse.ErrorMessage); } } catch (Exception ex) { log.Error(ex); throw; } }
public static void UserTimeline() { IAsyncResult asyncResult = TwitterTimelineAsync.UserTimeline( Configuration.GetTokens(), new UserTimelineOptions(), new TimeSpan(0, 2, 0), result => { TwitterStatusCollection timeline = result.ResponseObject; PerformCommonTimelineTests(result); }); asyncResult.AsyncWaitHandle.WaitOne(); UserTimelineOptions User_Options = new UserTimelineOptions(); User_Options.ScreenName = "twitterapi"; User_Options.Count = 8; TwitterResponse<TwitterStatusCollection> timelineResponse = TwitterTimeline.UserTimeline(Configuration.GetTokens(), User_Options); PerformCommonTimelineTests(timelineResponse); timelineResponse = TwitterTimeline.UserTimeline(User_Options); PerformCommonTimelineTests(timelineResponse); }
/// <summary> /// Gets current user (defined by access token) home timeline /// </summary> /// <param name="messageCount">Message count</param> /// <returns>Message list</returns> public List<Message> GetUserHomeTimeLine(int messageCount) { try { Twitterizer.OAuthTokens tokens = GetOAuthTokens(); Twitterizer.UserTimelineOptions options = new Twitterizer.UserTimelineOptions(); options.Count = messageCount; options.IncludeRetweets = true; TwitterResponse<TwitterStatusCollection> statusResponse = TwitterTimeline.HomeTimeline(tokens, options); if (statusResponse.Result == RequestResult.Success) return MapMessage(statusResponse.ResponseObject); else throw CreateException(statusResponse.Result, statusResponse.ErrorMessage); } catch (Exception ex) { log.Error(ex); throw; } }
/// <summary> /// Gets tweets posted by specified user /// </summary> /// <param name="messageCount">Message count</param> /// <returns>Message list</returns> public List<Message> GetUserTweets(decimal? userID, string screenName, int messageCount) { try { Twitterizer.OAuthTokens tokens = GetOAuthTokens(); Twitterizer.UserTimelineOptions options = new Twitterizer.UserTimelineOptions(); options.ScreenName = screenName; if (userID.HasValue) options.UserId = userID.Value; options.IncludeRetweets = true; options.Count = messageCount; TwitterResponse<TwitterStatusCollection> statusResponse = TwitterTimeline.UserTimeline(tokens, options); if (statusResponse.Result == RequestResult.Success) return MapMessage(statusResponse.ResponseObject); else throw CreateException(statusResponse.Result, statusResponse.ErrorMessage); } catch (Exception ex) { log.Error(ex); throw; } }
public static List<TwittStatus> GetTwittStatusList(string screenName) { OAuthTokens tokens = new OAuthTokens(); tokens.ConsumerKey = "zPY6AwGePUOWAk0fTvrhZhgzg"; tokens.ConsumerSecret = "VzBhawh55oWWocdDrn4MdLfSPcG5ypf7scFJZGrSyWkSuJAjDA"; tokens.AccessToken = "50022775-djO15EBUOMT76TXswKa0XvwfDmM12Xo27NZmxyhwr"; tokens.AccessTokenSecret = "QqpnD1Mq4AEQYW48NyauzAMDRGDyQ0QCTQjWNRFyFCZkz"; var list = new List<TwittStatus>(); UserTimelineOptions options = new UserTimelineOptions(); options.APIBaseAddress = "https://api.twitter.com/1.1/"; options.Count = 20; options.UseSSL = true; options.ScreenName = screenName; var resp = TwitterTimeline.UserTimeline (tokens, options); TwitterStatusCollection tweets = resp.ResponseObject; if (tweets == null) return null; foreach (var status in tweets) { TwittStatus ts = new TwittStatus ( status.Id.ToString (), status.Text, status.User.Id.ToString(), status.CreatedDate.ToString()); list.Add (ts); } return list; }
public ActionResult Index() { TwitterStatusCollection mattTweets = null; TwitterStatusCollection christyTweets = null; if (HttpRuntime.Cache["MattTweets"] == null) { UserTimelineOptions options = new UserTimelineOptions(); options.ScreenName = "mkchandler"; mattTweets = TwitterTimeline.UserTimeline(options).ResponseObject; HttpRuntime.Cache["MattTweets"] = mattTweets; } else { mattTweets = (TwitterStatusCollection)HttpRuntime.Cache["MattTweets"]; } if (HttpRuntime.Cache["ChristyTweets"] == null) { UserTimelineOptions options = new UserTimelineOptions(); options.ScreenName = "Mom2Emery_Liam"; christyTweets = TwitterTimeline.UserTimeline(options).ResponseObject; HttpRuntime.Cache["ChristyTweets"] = christyTweets; } else { christyTweets = (TwitterStatusCollection)HttpRuntime.Cache["ChristyTweets"]; } return View(new HomeViewModel(mattTweets, christyTweets)); }
/// <summary> /// Gets current user (defined by access token) home timeline /// </summary> /// <param name="messageCount">Message count</param> /// <returns>Message list</returns> public List <Message> GetUserHomeTimeLine(int messageCount) { try { Twitterizer.OAuthTokens tokens = GetOAuthTokens(); Twitterizer.UserTimelineOptions options = new Twitterizer.UserTimelineOptions(); options.Count = messageCount; options.IncludeRetweets = true; TwitterResponse <TwitterStatusCollection> statusResponse = TwitterTimeline.HomeTimeline(tokens, options); if (statusResponse.Result == RequestResult.Success) { return(MapMessage(statusResponse.ResponseObject)); } else { throw CreateException(statusResponse.Result, statusResponse.ErrorMessage); } } catch (Exception ex) { log.Error(ex); throw; } }
/// <summary> /// Returns the 20 most recent statuses posted by the authenticating user. It is also possible to request another user's timeline by using the screen_name or user_id parameter. /// </summary> /// <param name="tokens">The oauth tokens.</param> /// <param name="options">The options.</param> /// <returns> /// A <see cref="TwitterStatusCollection"/> instance. /// </returns> public static TwitterResponse <TwitterStatusCollection> UserTimeline( OAuthTokens tokens, UserTimelineOptions options) { Commands.UserTimelineCommand command = new Commands.UserTimelineCommand(tokens, options); return(Core.CommandPerformer.PerformAction(command)); }
/// <summary> /// Returns the 20 most recent statuses posted by the authenticating user. It is also possible to request another user's timeline by using the screen_name or user_id parameter. /// </summary> /// <param name="tokens">The oauth tokens.</param> /// <param name="options">The options.</param> /// <returns> /// A <see cref="TwitterStatusCollection"/> instance. /// </returns> public static TwitterResponse<TwitterStatusCollection> UserTimeline( OAuthTokens tokens, UserTimelineOptions options) { Commands.UserTimelineCommand command = new Commands.UserTimelineCommand(tokens, options); return Core.CommandPerformer.PerformAction(command); }
// Get all posts of a specific user public string GetResponse(RepositoryOptions options) { var opt = new UserTimelineOptions(); opt.ScreenName = options.twitterUser.screen_name; opt.IncludeRetweets = true; opt.Count = postCount; var response = TwitterTimeline.UserTimeline(GenerateAuthentication(), opt); return response.Content; }
public List <TweetExtended> getTweetsFrom(string id, TwUser usr) { var tokens = TwitrucHelpers.getTokens(usr); var o = new Twitterizer.UserTimelineOptions(); o.ScreenName = id; o.Count = 50; try { Twitterizer.TwitterResponse <Twitterizer.TwitterStatusCollection> userResponse = Twitterizer.TwitterTimeline.UserTimeline(tokens, o); if (userResponse.Content != null) { return(userResponse.ResponseObject.Select(st => new TweetExtended(st)).ToList()); } } catch (Exception) { } return(db.TweetSet.Where(t => t.AuthorNick == id).ToArray().Select(t => new TweetExtended(t)).ToList()); }
private TwitterStatusCollection getTwittergotchiDirectedOwnerTweets(String ownerName, String twittergotchiName) { TwitterStatusCollection directedToTwittergotchiTweets = new TwitterStatusCollection(); UserTimelineOptions options = new UserTimelineOptions(); options.ScreenName = ownerName; TwitterResponse<TwitterStatusCollection> userTimeline = TwitterTimeline.UserTimeline(options); TwitterStatusCollection userStatusCollection = userTimeline.ResponseObject; foreach(TwitterStatus userStatus in userStatusCollection) { if(userStatus.InReplyToScreenName == twittergotchiName) { directedToTwittergotchiTweets.Add(userStatus); } } return directedToTwittergotchiTweets; }
/// <summary> /// Returns the 20 most recent statuses posted by the authenticating user. It is also possible to request another user's timeline by using the screen_name or user_id parameter. /// </summary> /// <param name="options">The options.</param> /// <returns> /// A <see cref="TwitterStatusCollection"/> instance. /// </returns> public static TwitterResponse<TwitterStatusCollection> UserTimeline( UserTimelineOptions options) { return UserTimeline(null, options); }
/// <summary> /// Get the tweets from the Twitter object /// </summary> /// <param name="PageNumber"></param> /// <returns></returns> private TwitterStatusCollection FetchTweets(int PageNumber) { TwitterStatusCollection tweets = new TwitterStatusCollection(); //cache the tweets here if (Page.Cache[string.Format("Tweet-{0}-{1}", PageNumber,this.ScreenName)] == null) { //set the tokens here OAuthTokens tokens = new OAuthTokens(); tokens.ConsumerKey = this.ConsumerKey; tokens.ConsumerSecret = this.ConsumerSecret; tokens.AccessToken = this.AccessToken; tokens.AccessTokenSecret = this.AccessTokenSecret; UserTimelineOptions options = new UserTimelineOptions(); options.Count = this.TweetCount * PageNumber; options.Page = 1; options.ScreenName = this.ScreenName; //now hit the twitter and get the response tweets = TwitterTimeline.UserTimeline(tokens, options).ResponseObject; if (PageNumber == 1) { HttpContext.Current.Cache.Add(string.Format("Tweet-{0}-{1}", PageNumber,this.ScreenName), tweets, null, DateTime.Now.AddMinutes(Common.CACHEDURATION), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Normal, CacheRemovedCallBack); } else { HttpContext.Current.Cache.Insert(string.Format("Tweet-{0}-{1}", PageNumber,this.ScreenName), tweets, null, DateTime.Now.AddMinutes(Common.CACHEDURATION), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Normal, null); } } else { tweets = HttpContext.Current.Cache[string.Format("Tweet-{0}-{1}", PageNumber,this.ScreenName)] as TwitterStatusCollection; } return tweets; }
/// <summary> /// Returns the 20 most recent statuses posted by the authenticating user. It is also possible to request another user's timeline by using the screen_name or user_id parameter. /// </summary> /// <param name="tokens">The tokens.</param> /// <param name="options">The options.</param> /// <param name="timeout">The timeout.</param> /// <param name="function">The function.</param> /// <returns></returns> public static IAsyncResult UserTimeline(OAuthTokens tokens, UserTimelineOptions options, TimeSpan timeout, Action <TwitterAsyncResponse <TwitterStatusCollection> > function) { return(AsyncUtility.ExecuteAsyncMethod(tokens, options, timeout, TwitterTimeline.UserTimeline, function)); }
public TwitterStatusCollection GetHomeTimeline(string username, decimal lastStatusId) { TwitterResponse<TwitterStatusCollection> response; if (username != null) { UserTimelineOptions opts = new UserTimelineOptions(); if (lastStatusId > 0) opts.SinceStatusId = lastStatusId; opts.ScreenName = username; response = TwitterTimeline.UserTimeline(tokens, opts); } else { TimelineOptions opts = new TimelineOptions(); if (lastStatusId > 0) opts.SinceStatusId = lastStatusId; response = TwitterTimeline.HomeTimeline(tokens, opts); } if (response.Result == RequestResult.Success) { // show the timeline return response.ResponseObject as TwitterStatusCollection; } else { // exception } return null; }
/// <summary> /// Returns the 20 most recent statuses posted by the authenticating user. It is also possible to request another user's timeline by using the screen_name or user_id parameter. /// </summary> /// <param name="tokens">The oauth tokens. Leave null for an unauthenticated request.</param> /// <param name="options">The options. Leave null for defaults.</param> /// <returns> /// A <see cref="TwitterStatusCollection"/> instance. /// </returns> public static async Task<TwitterResponse<TwitterStatusCollection>> UserTimelineAsync(OAuthTokens tokens = null, UserTimelineOptions options = null) { return await Core.CommandPerformer.PerformAction(new Commands.UserTimelineCommand(tokens, options)); }
private TwitterResponse<TwitterStatusCollection> GetTwitterStatus() { TwitterResponse<TwitterStatusCollection> userInfo = new TwitterResponse<TwitterStatusCollection>(); //use cache here if (Page.Cache[string.Format("TweetWrite-{0}", this.ScreenName)] == null) { //create a authorization token of the user OAuthTokens tokens = new OAuthTokens(); tokens.ConsumerKey = this.ConsumerKey; tokens.ConsumerSecret = this.ConsumerSecret; tokens.AccessToken = this.AccessToken; tokens.AccessTokenSecret = this.AccessTokenSecret; //Set the query options UserTimelineOptions Useroptions = new UserTimelineOptions(); Useroptions.ScreenName = this.ScreenName; //Get the account info userInfo = TwitterTimeline.UserTimeline(tokens, Useroptions); HttpContext.Current.Cache.Insert(string.Format("TweetWrite-{0}", this.ScreenName), userInfo, null, DateTime.Now.AddMinutes(Common.CACHEDURATION), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Normal, null); } else { userInfo = Page.Cache[string.Format("TweetWrite-{0}", this.ScreenName)] as TwitterResponse<TwitterStatusCollection>; } return userInfo; }
/// <summary> /// 指定ユーザのタイムラインを取得 /// </summary> /// <param name="tokens">トークン</param> public IEnumerable<TwitterStatus> GetUserTimeline(string screenName) { try { UserTimelineOptions option = new UserTimelineOptions() { ScreenName = screenName, Count = 5 }; TwitterResponse<TwitterStatusCollection> res = TwitterTimeline.UserTimeline(this.tokens, option); foreach (TwitterStatus status in res.ResponseObject) { Console.WriteLine(status.Text); } return res.ResponseObject; } catch (TwitterizerException exp) { Console.WriteLine(exp.Message); throw; } catch { throw; } }
/// <summary> /// Returns the 20 most recent statuses posted by the authenticating user. It is also possible to request another user's timeline by using the screen_name or user_id parameter. /// </summary> /// <param name="tokens">The tokens.</param> /// <param name="options">The options.</param> /// <param name="timeout">The timeout.</param> /// <param name="function">The function.</param> /// <returns></returns> public static IAsyncResult UserTimeline(OAuthTokens tokens, UserTimelineOptions options, TimeSpan timeout, Action<TwitterAsyncResponse<TwitterStatusCollection>> function) { Func<OAuthTokens, UserTimelineOptions, TwitterResponse<TwitterStatusCollection>> methodToCall = TwitterTimeline.UserTimeline; return methodToCall.BeginInvoke( tokens, options, result => { result.AsyncWaitHandle.WaitOne(timeout); try { function(methodToCall.EndInvoke(result).ToAsyncResponse()); } catch (Exception ex) { function(new TwitterAsyncResponse<TwitterStatusCollection>() { Result = RequestResult.Unknown, ExceptionThrown = ex }); } }, null); }
public List<TweetExtended> getTweetsFrom(string id, TwUser usr) { var tokens = TwitrucHelpers.getTokens(usr); var o = new Twitterizer.UserTimelineOptions(); o.ScreenName = id; o.Count = 50; try { Twitterizer.TwitterResponse<Twitterizer.TwitterStatusCollection> userResponse = Twitterizer.TwitterTimeline.UserTimeline(tokens, o); if (userResponse.Content != null) { return userResponse.ResponseObject.Select(st => new TweetExtended(st)).ToList(); } } catch (Exception) { } return db.TweetSet.Where(t => t.AuthorNick == id).ToArray().Select(t => new TweetExtended(t)).ToList(); }
/// <summary> /// Returns the 20 most recent statuses posted by the authenticating user. It is also possible to request another user's timeline by using the screen_name or user_id parameter. /// </summary> /// <param name="options">The options.</param> /// <returns> /// A <see cref="TwitterStatusCollection"/> instance. /// </returns> public static TwitterResponse <TwitterStatusCollection> UserTimeline( UserTimelineOptions options) { return(UserTimeline(null, options)); }
public List<string> GetLastTweets(int nr) { UserTimelineOptions options = new UserTimelineOptions(); options.ScreenName = ScreenName; TwitterStatusCollection tweets = TwitterTimeline.UserTimeline(options).ResponseObject; List<String> tweetList = new List<string>(); int i = 0; foreach (var tweet in tweets) { tweetList.Add(tweet.Text); if (++i == nr) break; } return tweetList; }
public string[] GetTweet() { UserTimelineOptions options = new UserTimelineOptions {IncludeRetweets = false, SinceStatusId = lastTweetId}; TwitterResponse<TwitterStatusCollection> response = TwitterTimeline.UserTimeline(oAuthTokens, options); string[] values = new string[] { }; if (response.Result == RequestResult.Success) { TwitterStatusCollection statuses = response.ResponseObject; List<TwitterStatus> listStatuses = new List<TwitterStatus>(statuses); this.lastTweetId = listStatuses.Min(t => t.Id); TwitterStatus status = listStatuses.Find(t => t.Id == this.lastTweetId); values = new string[] { status.CreatedDate.ToShortDateString(), status.User.Name, status.Text }; } return values; }
public ActionResult Profile(String screenname) { if (Session["LoggedASP"] != null) ViewData["username"] = ((User)Session["LoggedUser"]).Username; try { TwitterResponse<TwitterUser> user; if (Session["LoggedTwitter"] != null) { OAuthTokens token = new OAuthTokens(); token.ConsumerKey = ConfigurationManager.AppSettings["consumerKey"]; token.ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"]; token.AccessToken = ((User)Session["LoggedUser"]).TwitterToken; token.AccessTokenSecret = ((User)Session["LoggedUser"]).TwitterTokenSecret; user = TwitterUser.Show(token, screenname); } else user = TwitterUser.Show(screenname); if (String.IsNullOrEmpty(user.ErrorMessage)) { ViewData["content"] = "<img class='userImg' src='" + user.ResponseObject.ProfileImageLocation.ToString() + "' />Profil de <em>@" + user.ResponseObject.ScreenName + "</em> qui possède l'ID N°" + user.ResponseObject.Id + "<br />Il s'est enregistré sur Twitter le : " + user.ResponseObject.CreatedDate + " et il possède " + user.ResponseObject.NumberOfFollowers + " followers."; UserTimelineOptions options = new UserTimelineOptions(); options.ScreenName = screenname; options.Count = 100; options.IncludeRetweets = true; if (Session["LoggedTwitter"] != null) { OAuthTokens token = new OAuthTokens(); token.ConsumerKey = ConfigurationManager.AppSettings["consumerKey"]; token.ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"]; token.AccessToken = ((User)Session["LoggedUser"]).TwitterToken; token.AccessTokenSecret = ((User)Session["LoggedUser"]).TwitterTokenSecret; bool taRaceVanStaen = false; if (screenname.ToLower() == TwitterUser.Show(token, Decimal.Parse(((User)Session["LoggedUser"]).TwitterID)).ResponseObject.ScreenName.ToLower()) taRaceVanStaen = false; TwitterResponse<TwitterStatusCollection> truc = TwitterTimeline.UserTimeline(token, options); if (String.IsNullOrEmpty(truc.ErrorMessage)) { foreach (var item in truc.ResponseObject) { if (taRaceVanStaen) ViewData["tweets"] += "<div class='editTweet'><a href=''>Edit</a> <a href=''>Delete</a></div><div><a href=\"/User/" + item.User.ScreenName + "\">" + item.User.ScreenName + "</a> ---- " + item.Text.Replace("\n", "<br />").ToString() + "</div>"; else ViewData["tweets"] += "<div><a href=\"/User/" + item.User.ScreenName + "\">" + item.User.ScreenName + "</a> ---- " + item.Text.Replace("\n", "<br />").ToString() + "</div>"; } } else ViewData["tweets"] = "Les tweets de cet utilisateur sont protégés."; } else { TwitterResponse<TwitterStatusCollection> truc = TwitterTimeline.UserTimeline(options); if (String.IsNullOrEmpty(truc.ErrorMessage)) { foreach (var item in truc.ResponseObject) { ViewData["tweets"] += "<div><a href=\"/User/" + item.User.ScreenName + "\">" + item.User.ScreenName + "</a> ---- " + item.Text.Replace("\n", "<br />").ToString() + "</div>"; } } else ViewData["tweets"] = "Les tweets de cet utilisateur sont protégés."; } return View("Index"); } else { ViewData["errorMessage"] = user.ErrorMessage; return View("Error"); } } catch (Exception exception) { ViewData["errorMessage"] = exception.Message; return View("Error"); } }
/// <summary> /// Returns the 20 most recent statuses posted by the authenticating user. It is also possible to request another user's timeline by using the screen_name or user_id parameter. /// </summary> /// <param name="tokens">The tokens.</param> /// <param name="options">The options.</param> /// <param name="timeout">The timeout.</param> /// <param name="function">The function.</param> /// <returns></returns> public static IAsyncResult UserTimeline(OAuthTokens tokens, UserTimelineOptions options, TimeSpan timeout, Action<TwitterAsyncResponse<TwitterStatusCollection>> function) { return AsyncUtility.ExecuteAsyncMethod(tokens, options, timeout, TwitterTimeline.UserTimeline, function); }
/// <summary> /// Returns the 20 most recent statuses posted by the authenticating user. It is also possible to request another user's timeline by using the screen_name or user_id parameter. /// </summary> /// <param name="tokens">The oauth tokens. Leave null for an unauthenticated request.</param> /// <param name="options">The options. Leave null for defaults.</param> /// <returns> /// A <see cref="TwitterStatusCollection"/> instance. /// </returns> public static async Task <TwitterResponse <TwitterStatusCollection> > UserTimelineAsync(OAuthTokens tokens = null, UserTimelineOptions options = null) { return(await Core.CommandPerformer.PerformAction(new Commands.UserTimelineCommand(tokens, options))); }