Pages

Tuesday, October 5, 2010

Twitter API, tweetsharp

For me, the most interesting thing about Twitter, is it allows those with interesting (albeit bite sized) data streams as wide an audience as they can reach, without the need for any sort of friend invite/accept protocol. The fact that it is almost completely one-way communication means there are not as many simultaneous conversation threads to deal with (between two users), as most information is either absorbed by followers or lost in cyberspace. The fact there is tons of data, some of it almost exclusive (until it is linked elsewhere) and the number of celebrities, (or other famous people) that the average joe would not be able to have any sort of connection to, seemingly breaks down the barriers and allows the twitterer to get information right from the horse's mouth, or whatever the case may be. This is much different from the Facebook model, where you can only really see your friends data streams. In twitter, you could follow more people than you could potentially meet in a lifetime. Naysayers should note, if Schwarzenegger is on Twitter, that should be good enough for almost everyone :P

Anyway, the big idea would be to code something using the Twitter API, and then tweet about it.

The first thing I noticed was how many examples on the web were out of date. Twitter's implementation of the OAuth (August 16, 2010), before it was much simpler, however safe is good too.

Some links I found useful, the main stuff from twipler is especially useful, and I use to show how to do a simple post based on the tweetsharp libs:

MAIN: http://blog.twipler.com/A34_Simple_Twitter_web_client_example.html
TWITTER SETUP: http://blog.twipler.com/A32_Registering_a_new_Twitter_application.html

LIBRARY:
http://dev.twitter.com/pages/basic_to_oauth
http://apiwiki.twitter.com/OAuth-Examples


Taking the twipler example we can add a small button to tweet.

1. In the interface file add another button (called btnTweet with the following values (if placed after the timeline button it will show up at line 18 of Default.aspx and will modify the designer page as well (go through the UI interface to avoid any issues.)

<asp:Button ID="btnTweet" runat="server" Text="Tweet" OnClick="btnTweet_Click">

2. Add the following code to Default.aspx.cs:
protected void btnTweet_Click(object sender, EventArgs e)
{
string response = Helper.Request(t => t.Statuses().Update(txtBox.Text), false);
litOutput.Text = "<h3>Tweet</h3>" + response;
}
3. Change the TweetSharpHelper.cs class CreateRequest method to public (instead of private).
public IFluentTwitter CreateRequest()
4. Set the ConsumerKey and ConsumerSecret if you haven't already.

5. Run the application and tweet away (type the message in the text box and hit tweet)!

Many will ask what this has to do with games... well, how many facebook games are there now? How many more with the Playstation Home and Mii's running around? Nearly every device will attempt to talk with every other eventually, and it will only be a matter of time before every headshot you register shows up on your twitter post, facebook wall and rss feed.

Follow me on twitter: http://twitter.com/#!/mayekol maybe I'll post something interesting sometime (but no promises :P)

Michael Hubbard
http://michaelhubbard.ca

No comments:

Post a Comment