Lately, I have been building a new Twitter site and it has been literally taking ALL of my time (and thus less blog posts) but let me give you TWO great sites that can help you get a head-start on making your own Twitter site too.
First, you will need to learn that Twitter API basically relies on RESTful HTTP protocol. Don’t worry about the funky name, it’s actually rather simple. You send a message to Twitter API and then you get a message back.
Now, there’s two ways to receive data back, one of XML and the other is JSON. JSON is supposedly better for AJAX application and faster as far as I know. (If I am wrong, please feel free to correct me in the comments please.)
Anyways, I have built StumbleTweets all based on XML but in trying JSON for my new Twitter site, I’ve had to resort to reading these two great articles for PHP:
- Digital-Web.com goes into detail of how easy it is to communicate with Twitter API plus the examples are explained well.
- After reading above, you will want to read Marks Kolich’s guide to JSON/PHP method to Twitter API. His method also includes file caching so you can save your Twitter API bandwidth. (Btw, Twitter API only allows up to so many API calls a day so you need to implement some kind of caching.)
As for Twitter API Caching, I think the best way to do it is actually cache the JSON/XML results first and limit your API calls to let’s say 5 minutes. Then you should really run any database MYSQL calls in the background so the user of the site doesn’t see any lag. I’ve tried to do it the other way where I would first store in the MySQL database but this turns out to be a no-no because when your database gets large, it takes virtually forever for the site to load.
Remember, I think using both file caching/database caching is required for most data-intensive Twitter sites but try to cache the data first then process it later.
Also, I see a lot of Twitter app sites that don’t cache the Twitter profile images. They really should just in case Twitter experiences fail whale.
Your Twitter app site should be built so it doesn’t go down just because Twitter goes down. It should have a back-up copy of everything(as cache), at least for another 2-3 hours.
Well, just some tips for those building a Twitter app site. 🙂
One Response to Twitter API DIY – How to Use Twitter API in PHP/JSON!
Leave a Reply

please send me the code that how to use twitter api in my project