diff options
Diffstat (limited to 'wired/old/published/Webmonkey/APIs/twitter.txt')
-rw-r--r-- | wired/old/published/Webmonkey/APIs/twitter.txt | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/wired/old/published/Webmonkey/APIs/twitter.txt b/wired/old/published/Webmonkey/APIs/twitter.txt new file mode 100644 index 0000000..86e0b4b --- /dev/null +++ b/wired/old/published/Webmonkey/APIs/twitter.txt @@ -0,0 +1,62 @@ +It's the hottest web service around and if you're looking to try out an API for the first time Twitter is a good place to start. + +Like the service itself, the Twitter API is simple and easy to use. The only thing to keep in mind is that Twitter limits you to 70 requests per 60 sixty minute interval so remember to cache or otherwise store your results or you may find yourself band. + +If you end up building something that needs to make more requests you can always e-mail Twitter and ask for permission. + + + +== Getting Started == + +Twitter's API is REST-based and will return results as either XML or JSON, as well as both RSS and ATOM feed formats. + +For a very simple look at the data returned fire up a terminal window and type: + +<code> +curl http://twitter.com/statuses/public_timeline.rss +</code> + +That line will give you the latest 20 tweets from the public timeline in the form of an RSS feed. To get the same results in JSON just change the extension to ".json". + +Public timelines can be accessed by any client, but all other Twitter methods require authentication. + + +=== Authenticating with Twitter === + +To authenticate yourself to Twitter you need to send a username and password. The basic format is: + +curl -u email:password http://twitter.com/statuses/friends_timeline.xml + +Most client libraries offer easy ways to pass in a username/password pair, making it very simple to authenticate with Twitter. + + +== Client Libraries == + +There's no need to re-invent the wheel and there are already some pretty good libraries out there for accessing Twitter. Whether you're looking for [http://twitter.com/help/api ActionScript], [http://code.google.com/p/python-twitter/ Python], [http://groups.google.com/group/twitter-development-talk/web/twitter4r-open-source-ruby-library-for-twitter-rest-api Ruby], [http://twitter.pbwiki.com/Scripts#PHP PHP] and [http://twitter.pbwiki.com/Scripts many more]. + +For the sake of example we'll use the Python library. Download and install the library and fire up a terminal window. + +Let's grab your last twenty tweets, fire up Python and type the following line, replacing "youusername" with your username: +<code> +>>> import twitter +>>> client = twitter.Api() +>>> latest_posts = client.GetUserTimeline(yourusername) +>>> print [s.text for s in latest_posts] +</code> +The last line prints out just the text of your posts. To get at things like date pasted and other useful methods, have a read through the [http://static.unto.net/python-twitter/0.5/doc/twitter.html Python library documentation]. + +To go the other direction, posting something to Twitter we'll need to authenticate. Recreate our Twitter client, but this time pass in your username and password: +<code> +>>> client = twitter.Api(username='yourusername', password='yourpassword') +>>> update = client.PostUpdate('The Twitter API is easy') +</code> + +Head over to your Twitter page and you should see the update. + +== Mashups, Apps and more == + +To get some idea of what you can do with the Twitter API, head over the fan wiki and check out some of the [http://twitter.pbwiki.com/Apps applications] and [http://twitter.pbwiki.com/Mashups mashups] that Twitterheads have created. + +One area of particular usefulness is the hashtags concept. Hashtags involve inserting a # sign to denote keywords or other data like location. Although not everyone is a fan of hashtags (they tend to make your tweets less readable) parsing Twitter streams for hashtags can yield a wealth of useful data. + +Some of the client libraries include functions to parse hashtags, but in many case you may have to write your own functions (have a look at the webmonkey primer on regular expressions, it might come in handy?)
\ No newline at end of file |