Using the Twitter API with PHP

by admin on April 5, 2009

in Social Media

What’s the Twitter API? We’ve all heard about how powerful Twitter can be because of the functions it provides to other applications using its API. Popular applications using the Twitter API include such websites as Twhirl, Twitturly and Hashtags.org.

API actually stands for Application Programming Interface. APIs act as an interface between applications or pieces of software. What this means is that Twitter offers a way for other websites to talk to its website through an interface. This helps other websites send to and retrieve information from Twitter.

That’s great, you may think, but how can I use it? Well that’s what we’re going to talk about today. One of the easiest way of testing the Twitter API for yourself is to create a simple PHP script to use Twitter’s search. This is for beginners, so if you’re good at PHP you might find this little example a bit too easy.

In this example, we’re going to tell Twitter to run a search for cats and then read the resulting data into a file.

Create a PHP file and copy the following code in it:

<?php

$data= ‘http://search.twitter.com/search.json?q=cats’;
$content = file_get_contents($data);
echo $content;

?>

Run this code and see what it does. Congratulations, you’ve just extracted your first piece of information from Twitter’s search function using its API!



Leave a Comment

Previous post:

Next post: