Tuesday, October 8, 2013

Post to twitter programatically with 3 lines of Code!

  1. Create a new web application
  2. using Nuget manager, download/install Tweetsharp
  3. Create a twitter application by visiting https://dev.twitter.com/apps/new
  4. Go to your twitter app settings, and make sure it's a read/write app
  5. Go to "Reset Keys" tab and reset keys, so the permission of read/write works with the new keys
  6. Generate Access Token and the first tab in your twitter settings
  7. Write the following Code, *Replace Dashes with your app keys, from the previous steps
using TweetSharp;
        //Store Keys
        string consumerKey = "-------";
        string consumerSecret = "-------";
        string accessToken = "-------";
        string accessTokenSecret = "-------";
        //Authenticate with twitter as your app.
        var service = new TwitterService(consumerKey, consumerSecret);
        service.AuthenticateWith(accessToken, accessTokenSecret);
        //Post Tweet
        var status = service.SendTweet(new SendTweetOptions { Status = "My Second #Tweet from Code :D" });
-- You can use the status variable to know the id of you posted status etc.