/// <summary> /// Gets the user that logged into Twitter and then checks to see if an error has occurred. /// </summary> /// <param name="service">A <see cref="TwitterService"/> used to call the Twitter API.</param> /// <returns>A <see cref="TwitterUser"/> representing the user that is logged in.</returns> public static TwitterUser GetCurrentUser(TwitterService service) { TwitterUser user = service.GetUserProfile(new GetUserProfileOptions()); TwitterAPIUtility.CheckError(service); return(user); }
/// <summary> /// Initializes a new instance of the <see cref="TweeterTottersViewModel"/> class. /// </summary> public TweeterTottersViewModel() { InitializeCommands(); service = TwitterAPIUtility.CreateAndAuthenticateService(System.Configuration.ConfigurationManager.AppSettings["ConsumerKey"], System.Configuration.ConfigurationManager.AppSettings["ConsumerSecret"]); CurrentUser = TwitterAPIUtility.GetCurrentUser(service); Refresh(); }
/// <summary> /// Gets a collection of the most recent profile page Tweets. /// </summary> /// <param name="service">A <see cref="TwitterService"/> used to call the Twitter API.</param> /// <returns>A <see cref="IEnumerable"/> of Twitter Status' on the user's profile page.</returns> public static IEnumerable <TwitterStatus> GetProfilePageTweets(TwitterService service) { IEnumerable <TwitterStatus> tweets = service.ListTweetsOnUserTimeline(new ListTweetsOnUserTimelineOptions()); TwitterAPIUtility.CheckError(service); return(tweets); }
/// <summary> /// Refreshes the Tweets loaded to the application. /// </summary> private void Refresh() { HomePageTweets = TwitterAPIUtility.GetHomePageTweets(service); ProfilePageTweets = TwitterAPIUtility.GetProfilePageTweets(service); IsTruncatedToIsRetweetedHack(HomePageTweets); IsTruncatedToIsRetweetedHack(ProfilePageTweets); }
/// <summary> /// Favorites the Tweet specified. /// </summary> /// <param name="service">A <see cref="TwitterService"/> used to call the Twitter API.</param> /// <param name="tweetId">A <see cref="long"/> representing the id of the Tweet to favorite.</param> public static void Favorite(TwitterService service, long tweetId) { service.FavoriteTweet(new FavoriteTweetOptions() { Id = tweetId }); TwitterAPIUtility.CheckError(service); }
/// <summary> /// Deletes the Tweet specified. /// </summary> /// <param name="service">A <see cref="TwitterService"/> used to call the Twitter API.</param> /// <param name="tweetId">A <see cref="long"/> representing the id of the Tweet to delete.</param> public static void DeleteTweet(TwitterService service, long tweetId) { service.DeleteTweet(new DeleteTweetOptions() { Id = tweetId, TrimUser = true }); TwitterAPIUtility.CheckError(service); }
/// <summary> /// Sends a new Tweet. /// </summary> /// <param name="service">A <see cref="TwitterService"/> used to call the Twitter API.</param> /// <param name="text">A <see cref="string"/> representing the text of the Tweet.</param> /// <param name="replyId">A <see cref="long"/> representing the Tweet that you're replying to. When this value is 0, it is not replying to anyone.</param> public static void Tweet(TwitterService service, string text, long replyId) { service.SendTweet(new SendTweetOptions() { Status = text, InReplyToStatusId = replyId }); TwitterAPIUtility.CheckError(service); }
/// <summary> /// Deletes the specified Twitter status. /// </summary> /// <param name="deleteTweet">A <see cref="TwitterStatus"/> representing the status to be deleted.</param> public void ExecuteDelete(TwitterStatus deleteTweet) { requestInProgress = true; TwitterAPIUtility.DeleteTweet(service, deleteTweet.Id); Refresh(); requestInProgress = false; }
/// <summary> /// Retweets the specified Twitter status. /// </summary> /// <param name="retweetTweet">A <see cref="TwitterStatus"/> representing the status to be retweeted.</param> public void ExecuteRetweet(TwitterStatus retweetTweet) { requestInProgress = true; TwitterAPIUtility.Retweet(service, retweetTweet.Id); retweetTweet.IsTruncated = true; Refresh(); requestInProgress = false; }
/// <summary> /// Sends the current Tweet. /// </summary> public void ExecuteTweet() { requestInProgress = true; TwitterAPIUtility.Tweet(service, CurrentTweet, TweetIdToReplyTo); CurrentTweet = string.Empty; TweetIdToReplyTo = 0; Refresh(); requestInProgress = false; }
/// <summary> /// Favorites or unfavorites the specified Twitter status. /// </summary> /// <param name="favoriteTweet">A <see cref="TwitterStatus"/> representing the status to be favorited.</param> public void ExecuteFavorite(TwitterStatus favoriteTweet) { requestInProgress = true; if (favoriteTweet.IsFavorited) { TwitterAPIUtility.Unfavorite(service, favoriteTweet.Id); favoriteTweet.IsFavorited = false; } else { TwitterAPIUtility.Favorite(service, favoriteTweet.Id); favoriteTweet.IsFavorited = true; } requestInProgress = false; }
/// <summary> /// Passes my registered application credentials to Twitter and then authenticates the user using OAuth. /// </summary> /// <param name="consumerKey">A <see cref="String"/> provided by Twitter which represents the API key associated with Tweeter Totters.</param> /// <param name="consumerSecret">A <see cref="String"/> provided by Twitter that authenticates the application access to Twitter.</param> /// <returns>An authenticated <see cref="TwitterService"/> that can now be used to to call the Twitter API.</returns> /// <remarks>The Consumer Secret Key is not meant to be public but as a random GitHub project, I see no repercussions.</remarks> public static TwitterService CreateAndAuthenticateService(string consumerKey, string consumerSecret) { TwitterService service = new TwitterService(System.Configuration.ConfigurationManager.AppSettings["ConsumerKey"], System.Configuration.ConfigurationManager.AppSettings["ConsumerSecret"]); OAuthRequestToken requestToken = service.GetRequestToken(); Uri uri = service.GetAuthorizationUri(requestToken); Process.Start(uri.ToString()); string verifier = Interaction.InputBox(Properties.Resources.PinLoginMessage, Properties.Resources.PinLoginTitle, null); OAuthAccessToken access = service.GetAccessToken(requestToken, verifier); service.AuthenticateWith(access.Token, access.TokenSecret); TwitterAPIUtility.CheckError(service); return(service); }