/// <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> /// 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> /// 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> /// 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); }