Erica Douglass, entrepreneur and writer About Erica Contact Erica Erica's Goals Erica's Public Speaking erica.biz Archives Erica Douglass

Welcome! I'm Erica Douglass. I am committed to teaching you how to build an inspired, successful business. I would love to hear your opinions and help you grow your business. If you are motivated to change the world and want to learn from my successes (and failures!), please subscribe and join my community!

Exposing the Twitter XML API with PHP

Recently Robert Scoble was complaining about how hard it was to add all of his Twitter followers as friends automatically. I figured it should be pretty easy to script. Well, it should be, but Twitter makes it unnecessarily complicated.

First, the Twitter API is marginally useful, but doesn’t let you actually do much besides passively read and post updates. I used the followers list XML and created a PHP script that snarfed the XML and put it in an associative array. My intent was to create a new followers page where you could check a box next to each follower (with a handy “Select All” button as well) and one-click to add those followers as friends.

Unfortunately, Twitter does not expose the login portion of the API, and just going to http://twitter.com/friendships/create/[follower ID number] without first going to the friend’s page redirects you back to your Twitter home page — even when you’re already logged in to Twitter! This is really broken — the Twitter API should let you work with their URLs.

Since Twitter’s API is completely useless for adding friends, and their interface doesn’t seem to allow for going directly to a URL to add a friend, I am stuck. However, I am happy to release the PHP code I wrote so that others can play around with Twitter’s API.

I grabbed the XML parser from a page on php.net — this is actually very useful to parse ANY XML document into a multi-dimensional associative array in PHP. My source code works. Right now it takes your username and password, sends that to Twitter, gets a list of your followers and displays them in a table, along with the correct link to add that friend (which, of course, doesn’t work because Twitter won’t accept it.)

It is my hope that Twitter will make their URLs and API much more useful in the future so that this sort of thing becomes easy. My script goes a long way toward making that possible on the client side, at least.

My source code
The XML parser I used

See the script in action! (Enter your Twitter username and password to get a list of your followers.)

This script is free to use, borrow, tweak, and hopefully will spur the Twitter developers into action and make them realize the importance of creating a better API.

Like this entry? Subscribe to this blog and receive an email update whenever a new post appears on the site! No spam, and I won't give your email address to any other company.

Email This Post To A Friend Email This Post To A Friend

book mark Exposing the Twitter XML API with PHP in del.icio.usBookmark in Del.icio.us  |   See this page in technoratiTechnorati  |   submit Exposing the Twitter XML API with PHP to digg.comDigg This!  |   review Exposing the Twitter XML API with PHP on StumbleUponReview on StumbleUpon


Previous post in this category:

4 Responses to “Exposing the Twitter XML API with PHP”

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 

Google