Twitter Search API And jSON Callbacks
Over the weekend I integrated a Twitter Profile Search Tool in my blog using the Twitter API and the jSON callback functions. What it does, is let you search Twitter profiles right from my blog, and display their latest Tweets. I have full control over the number of tweets to display, the amount to show, and more. The Twitter API and jSON functions are very cool, and this is only the beginning to what can be done with it. I started with a search tool because it is a very practical thing to make. Let’s dissect it a bit to see how it was done.
First off, what is the Twitter API, and what can I do with it?
Well simply put, Twitter exposes some of its functionality via an Application Programming Interface (API). This allows us so to some cool things with it, like my Twitter Profile Search Tool.
Lets get dirty.
There are a few things that must be included to get this to function correctly. Here is a quick overview.
We need to have a search field and button to submit, lets use “user” as the search fields name.
We then need to place < ?php $user = $_GET['user']; ? > high up on our code. This will grab the variable $user to send through the API and jSON, giving us the profile we would like to search.
Inside the form action we need to do method=”GET” and action=”&user=”. This will add the variable user to the URL and encode it to manipulate the data.
Next we need to include an element with an ID called “twitter_update_list” I chose to use an Unordered List. jSON will look for this ID and know where to place the called data.
We are just about done, here is the last chunk of code.
< ?php echo " “; ? >
I converted the last javascript line to PHP because I wanted to make it dynamic. You see how there is “$user.json?” typicly in a static call, $user would be an actual profile name. But since I wanted to make it a dynamic call and enable the user to search for themselves, I added the profile name a variable.
The last part to this is to change count to the number you want to display. 20 = 20 Tweets.
The End Result:
Twitter Updates From:
What Now?
I have created a code document you can download right from here: Twitter Search Tool. It works right out of the box. Have fun with it and see what you can do to make Twitter a better application and micro-blogging tool.
That’s about it. That’s the user profile search in a nutshell. Have any questions or suggestions? Let me know in the comments below.
I may even port this out to make it an Adobe AIR app with some improvements.