Learning to Love the API: Social

Thursday, October 7th, 2010

You can also control your social world through the API. As you might expect Facebook has an extensive API. Personally, though, I am more of a Twitter fan ;)

The API for twitter used to be simple. You could simply pass a username and password to issue most commands. Here, we are adding a friend from the command line:

curl -u username:password -d "" http://twitter.com/friendships/create/30664308.xml

It was equally simply to automate posting. The following is a snippit from my (now defunct) plugin TwitCategory:

//Standard curl function, handles actual submission of message to twitter
function twitcategory_postMessage( $twitter_username, $twitter_password, $message ){
	$url = 'http://twitter.com/statuses/update.xml';
	$curl_handle = curl_init();
	curl_setopt( $curl_handle, CURLOPT_URL, "$url" );
	curl_setopt( $curl_handle, CURLOPT_CONNECTTIMEOUT, 2 );
	curl_setopt( $curl_handle, CURLOPT_RETURNTRANSFER, 1 );
	curl_setopt( $curl_handle, CURLOPT_POST, 1 );
	curl_setopt( $curl_handle, CURLOPT_POSTFIELDS, "status=$message&source=twitcategory" );
	curl_setopt( $curl_handle, CURLOPT_USERPWD, "$twitter_username:".str_rot13( $twitter_password ) );
	$buffer = curl_exec( $curl_handle );
	curl_close( $curl_handle );
}

However, they now require you to use OAuth to authentication your applications. This is safer for users, but does complicate things for developers…

One Response to “Learning to Love the API: Social”


  1. gabriel nagmay (dot com) | Archive » Learning to Love the API Says:

    […] Social (Twitter) […]

Leave a Reply

You know you want to...