The Auros Blog

28Sep2011

Experiencing the Twitter API

Twitter birdEveryone here at Auros is bubbling with enthusiasm about the exciting strides we're making in the  internet technologies, but I'm especially excited about  my involvement in the Twitter API projects we've got on the go..

In this blog I'll talk mainly about some of the experiences of developing against the Twitter API for some exciting upcoming services that we'll be providing to our customers, and talk through the simple stages that you need to follow when interacting with Twitter.

First Step

Provide ourselves with some test accounts and then set up a test application on one of the test accounts so we  can get going as soon as the provisions are in place.

To set up the Twitter application just go to https://dev.twitter.com/apps and create your very own fully functional gateway.

Tool Up

The next step to successful software interaction with Twitter is to choose a suitable toolkit to access the Twitter API. This will do all the heavy lifting jobs. As ever with software, the last thing we want is to re-invent the wheel. A couple of toolkits turned up (we're .Net so check out the toolkits) and the most lightweight was Twitterizer, and taking it for a test drive turned out very good indeed and perfectly suited to our needs. From here the development process is extremely straight forward as you’ll see / read…

The boundaries

Using the mention search as an example we need to gather the data but not process information we've already gathered, so we can achieve this by setting up a TimelineOptions object which is hugely important to provide the boundary parameters. Some parameters that should be used are listed below:

  • Since Status Id - this will provide the delta parameter: the from point to now
  • Count - allowing us to collect enough but not too much at a time
  • Page - if we reach our count value, we can get the next page of results
  • IncludeRetweets - do we really?
  • APIBaseAddress - we can actually specify the base URL

More about the APIBaseAddress… There are two ways to search on Twitter, either use the Twitter search API (http://search.twitter.com/) or use the API mentions/timeline search (http://api.twitter.com/1/).  By being able to specify the API base address is quite handy when you have a preference and rumours were that the search API was not as efficient (see service status for comparing the two)!  If unfounded please comment, but either way we opted for the later for doing the search. Fiddler can be used to confirm that this is actually the case.

Simple toolkit example of a call to the API to get a list of mentions:

https://gist.github.com/1247580

The list of mentions can be a little unordered, so best to order, which also makes it easier to obtain the last since id ready for use in the next search.

https://gist.github.com/1247585

Cool, now the tweets can be processed for the information we want. The business logic end of the process which will want to be managed, interchanged, add new features, extend, etc.

The real deal

When everything is in place there are a couple of ways to sign up your clients. The most common approach is to use authentication access.  If your client has registered with your application through a registration process (see Twitter application permission model) then you'll have a set of consumer and access keys which can be plugged straight into the authentication container, if not and they've just passed over their tokens to you then these will just slot in too as the format of the authentication is the same, just that all the keys will be from the client. More about the Open Auth authentication process in my next blog.

If you want to write tweets, naturally the application must be read/write for the access part of the application.  If it is read only you'll get an error telling you so. Make sure to log all your error messages to diagnose these little simple issues that tend to trip you up. We use log4net which is a great open source utility.

Rules is rules

Don't forget the rules list and guides on how to manage the use of Twitter through your application, because Twitter is policing your usage, especially if you’re performing automation operations. Check out the Twitter policies, guidelines, and best practices for more information.

Much, much more...

You're probably gonna want to put a front end to your services with maybe some of the following:

  • an administration dashboard so that you can manage and monitor everything
  • run usage and status reports
  • provide customer secure access to run their own usage reports
  • allow additional decision making business process modules to be plugged in
  • even allow customers to purchase some of the exciting and useful modules on offer

Hope this was useful.

 

Comments (0) Trackbacks (0)

No comments yet.

Leave a comment


No trackbacks yet.