How can I send a tweet from an unattended C# application? So far, I've tried TweetSharp, but that isn't working for me (no errors, but no success either). Here's the background info... I have set up two twitter accounts to test this (lets call them TwitterSender and TwitterReceiver). TwitterReceiver is "following" TwitterSender. I went to dev.twitter.com and logged in as TwitterSender and clicked the "Create New App" button. From here, I was able to find things called "API Key", "API Secret", "Consumer Key", "Consumer Secret", "Access Token", and "Access Token Secret". When I'm logged in as TwitterSender I can see that I have granted read/write/direct message access. How can I tie all this together so that I can simply run the C# console application and have it send a tweet ("Hello World!") from TwitterSender so that any followers (e.g. TwitterReceiver) will get it? I'm OK with hard-coding user/password in plain-text. In the code below, I get no errors at all, but ultimately TwitterStatus ends up being null, and there is no indication that a tweet was sent either from the perspective of TwitterSender or TwitterReceiver.
TwitterClientInfo twitterClientInfo = new TwitterClientInfo();
twitterClientInfo.ConsumerKey = ConsumerKey; //Read ConsumerKey out of the app.config
twitterClientInfo.ConsumerSecret = ConsumerSecret; //Read the ConsumerSecret out the app.config
TwitterService twitterService = new TwitterService(twitterClientInfo);
twitterService.AuthenticateWith(AccessToken, AccessTokenSecret);
Console.WriteLine("Enter a Tweet");
string tweetMessage;
tweetMessage = Console.ReadLine();
TwitterStatus twitterStatus = twitterService.SendTweet(tweetMessage);
I got this working finally! In short, to send a tweet from, say, a Windows form without requiring a user to log in, you would do the following:
Write your code. For example, in a button click event...
var service = new TweetSharp.TwitterService("ConsumerKey","ConsumerSecret","TokenKey","TokenSecretKey"); //Replace keys with values from step #5
var twitterStatus = service.SendTweet(new SendTweetOptions() { Status ="Hello World" });
if (twitterStatus != null)
{
MessageBox.Show("It worked");
}
Note - You can't send the exact same tweet more than once per ___ (some undocumented amount of time). When there is an authentication problem, twitterStatus will return null - if that happens, check your keys, perhaps repermission and regenerate them again.