TwitAPI: A Twitter API Extension

I just presented at BarcampLondon2 on a little API extension I've been working on as a hobby for Twitter called TwitAPI. I found the official Twitter API slightly limiting when playing around with Friend or Follower. Specifically, there isn't a way to get a list of someone's friends without actually having their login information. And there's no support for adding, removing, following and leaving friends. Well, there wasn't, until TwitAPI :)

Basically, TwitAPI does the ugly work behind the scenes and gives you a simple API for accessing these features. Thanks to Amfphp, you get a Flash Remoting and JSON interface. And, for the getFriends call, I created an XML option as well.

Here are some brief docs if you want to start working with it right away (if anyone's going to do anything with it at BarcampLondon2, feel free to find me here.)

JSON endpoint:

http://aralbalkan.com/twitapi/json.php

Methods:

getFriends (userName)

Usage:

http://aralbalkan.com/twitapi/json.php/Twitter.getFriends/userName

Example:

http://aralbalkan.com/twitapi/json.php/Twitter.getFriends/aral

userName: User name of the user to get the friends list for. Returns an array of objects with id, userName, fullName, imageName, normalImageUrl properties.

You can also access the friends list in XML (see below).

addFriend (friendUserId, friendUserName, yourUserName, yourPassWord)

Usage:

http://aralbalkan.com/twitapi/json.php/Twitter.addFriend/friendUserId/friendUserName/yourUserName/yourPassWord

Returns:

True or false, depending on whether the user was successfully added.

The removeFriend, followFriend and leaveFriend methods work in exactly the same way and take exactly the same arguments.

In case there's a worry about security: Yes, you're passing your Twitter username and password in plain text in the GET string but your username and password get passed in plain text via basic authentication in the header with Twitter in any case so it's no less or more secure than Twitter in general (which is basic authentication over http so it's not secure.)

XML service

The getFriends method has an XML service too:

http://aralbalkan.com/twitapi/get_friends_xml.php

Usage:

http://aralbalkan.com/twitapi/get_friends_xml.php?user=userName

Example:

http://aralbalkan.com/twitapi/get_friends_xml.php?user=aral

Flash Remoting gateway

There is also a Flash Remoting gateway that you can use with the same methods. Details are in the AMFPHP Service Browser (ignore the username and password text inputs in the interface -- that's for testing basic authentication).

Comments