Recently, I’ve been developing a new Twitter app site and found some great resources on Twitter API. Believe me, this isn’t my first Twitter app ever so I have some experience dealing with Twitter API.
First off, you will want to start learning how to use the Twitter API via curl. Curl is basically a linux/PHP command that allows you to retrieve other web pages to the web server. This would be way your web server actually communicates with Twitter API.
Simply put it, your web server ask for a webpage such as http://twitter.com/user/statuses and would get back some of of user statuses in the format of XML and JSON. (Btw, the webpage URL is just made up in this example.)
XML and JSON are simply how data are formatted so you can easily access it. I have used both XML and JSON for receiving data and I would have to say to learn both but use JSON if you can as it’s faster. (Plus Twitter team also recommends JSON over XML)
So the very first thing I want you to do (if you don’t know how already), is to learn how to use the Twitter API via Curl. Try this guide on MoreThanSeven.Net. It should only take you 15-30 minutes to try out the code and get somewhat familiar with how simply Twitter API is and how it works.
Of course, don’t forget, you need “Curl” installed on your web server. From linux command line, simply do “yum install curl” for Fedora/CentOS and probably “sudo apt-get install curl” on Ubuntu/Debian.
Once you have mastered that Curl API method, you will want to learn about “caching”. If you don’t “cache” your API requests, you will eventually run out of API requests very quickly and your Twitter app will come to a screeching halt. You don’t want that so let’s learn to “cache” the API requests itself. Mark Kolich has a great guide Twitter Caching which comes with some of the basic API request functions. Somewhat different from the previous Curl guide but this will help you get some ideas on how to “cache” your API requests.
AND/OR you can setup a file caching system that will cache every PHP file in your web server. This way, if a webpage gets more than 1 hit, it will load super-fast. You can follow the PHP File Caching guide here. Also note that you can actually include the files cache.php and endcache.php on the header and footer of your file to cache if you don’t feel like using .htaccess or use non-Apache servers Nginx or Lighttpd like I do.
I am sure after trying all of the above, you will come up with a method to cache all your web pages efficiently as possible. (This will save you a ton of money on servers if your Twitter app site gets HUGE.)
Now you got the basics out of the way, you will want to learn how to authenticate Twitter users using the OAuth Twitter API. This is simply a method for authenticating your Twitter users without them typing in their Twitter username/password into your site. Plus, by using OAuth, you have to benefits of adding “from MyTwitterAppSite.com” instead of the default “from web” or “from API” under tweet signatures.
I’ve tried a bunch of OAuth guides out there and the best one (that actually worked) is Twitter-Async by Jaisen Mathai. Btw, don’t download the source code using the zipped file, download the “latest” files under source. (Or copy and paste every file like I did) The zipped file comes with older files that don’t work.
Also, there’s a PHP 5.2 requirement for Twitter Async. If you are running PHP 5.1.6 or below, you might want to upgrade before trying. Btw, PHP 5.2 runs JSON natively and runs like 20 times faster than PHP 5.1.6 so you have every reason to upgrade to PHP 5.2. If you are running on CentOS, try my guide on how to upgrade PHP 5.1.6 to 5.2 here.
To check your PHP version, do “php -v” at linux command line.
Also, another note on OAuth in general. You need to set your web server time correctly otherwise Twitter OAuth won’t communicate with you. Make sure your web server has correct date and time! (I spent about 10 hours trying to figure out why I kept getting failed authentications and my web server time was too fast by 2 hours.)
Twitter-Async also comes with dynamic way of calling API plus ability to send API calls in “parallel” or asynchronously. (This means you can do 5 API calls in 1 API call time, much faster than doing one by one.) One thing that’s missing from the API is caching and I think it shouldn’t be too hard to hack one in.
My advice is to use the OAuth code separately only for logged in users and use simpler “cached” Curl library (I use the Mark Kolich’s Twitter Cacher code for non-users) for visitors that are not logged in.
Whatever the case, you will want to learn the basic of Twitter API I have outlined here and practice it. Once you get the hang of it, make a good plan of how you will make your overall Twitter app site.
Good luck and I have just provided you with some of the best Twitter API guides/tips so you got nothing to lose! Feel free to ask me any questions on the comments line.