예제 #1
0
        /// <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);
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
 /// <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);
 }
예제 #4
0
 /// <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);
 }
예제 #5
0
 /// <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);
 }
예제 #6
0
        /// <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);
        }