We could be discussing about why twitter is a success, or talking about the utility of twitter, but this is a blog about programming, that’s why I prefer to talk about how to use twitter API to do your own applications.
Mainly, the only thing you need to know is that twitter has 2 APIs:
- REST: is an API that allows you to do simple queries and get paginated set of results
- Streaming: is an API that allows you to capture in real time the twits (is kind of alpha, but works well).
Both APIs provide interesting functions. Twitter API is open to anyone who has a twitter account. If you can twit, you can access the API. Even if you do not have any twitter account, there are several methods that could be called without credentials.
Finally, in PHP is really easy to open a URL, so calling the API of twitter is as easy as:
$api_url = "http://search.twitter.com/trends/current.json";
$result = file_get_contents ($api_url);
echo $result;
Even, if the call you are trying to do, requires authentication, it will be as simple as:
$auth = "username:password"; // your username/password of your twitter account
$api_url = "http://" . $auth . "@search.twitter.com/trends/current.json";
$result = file_get_contents ($api_url);
echo $result;
Another way of accessing the API (or opening URLs) would be using CURL, which is an excelent but more complex library. But why writing 10 to 12 lines of code when you can do it in 2?
Links of interest:
Español
One Comment on "Twitter API using PHP"