Pages

Tuesday, March 26, 2013

How to get tweets

I do not have twitter account yet and thus I was not thinking about the possibilities of integration it into applications. However, recently I was watching video about M# and I was really impressed about it. So I decided to try to get tweets.

Here is the simplest attempt:

public void LoadNewsLine(string username)
{
    WebClient twitter = new WebClient();

    twitter.DownloadStringCompleted += (sender, e) =>
        {
            XElement xmlTweets = XElement.Parse(e.Result);

            var message = from tweet in xmlTweets.Descendants("status")
                            select tweet.Element("text").Value;
        };
    twitter.DownloadStringAsync(new Uri(string.Format("http://api.twitter.com/1/statuses/user_timeline.xml?screen_name={0}", username)));
}


And you can get the information about the user with this request: "https://api.twitter.com/1/users/profile_image?screen_name=USERNAME". You can also add "&size=bigger" to request a bigger image :)

But if you need something more complex you should check tweetsharp In order to not to reinvent the wheel.