Back in 2009, I wrote a post on how to write a simple PHP script to call on the Twitter API and update your status. Despite its popularity, the information hasn’t been relevant in some time. (Things certainly have changed since then!) The Twitter API has changed a lot over the years, and it’s not so simple that you can get a newbie up and running with a few lines of code.
The mandatory usage of OAuth tokens, rather than a simple username and password combination, for API requests has greatly strengthened account security, but it’s one of the prime hurdles complicating the process. More recently, XML support was removed in favor of JSON, URL structures changed to include an API version, and authentication is now required for every request.
Fortunately, you don’t have to deal with the little details. You can use a library that does the heavy lifting for you, rather than reinventing the wheel. Sure, there are resources to learn how to do it the hard way, but I assume that you want a quicker solution if you’re reading this.
Step 1: Download tmhOAuth
Download the tmhOAuth library from GitHub. This package will handle interactions with the Twitter API once you include it from your script. (It requires at least PHP 5.1.2 and the cURL extension.)
Continue reading →