Archive for the ‘Twitter Apps’ Category



Your Complete HOWTO Guide to Twitter API using PHP and Javascript/AJAX!

January 26th, 2010

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.

I’ve begun to realize more and more that there’s a lot of great Twitter API resources out there but none are so “complete” for PHP/AJAX programmers out there.  It’s basically a big maze out there for someone who’s just testing out the Twitter API waters but let me give you some great sites and tips on how to get started with Twitter API using PHP and/or javascript/AJAX.

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.)

Another way you can also optimize your server for heavy traffic is to install Lighttpd or Nginx.  See how to install Lighttpd here and how to install Nginx here.

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.

One more thing, make sure you call for authorization tokens on OAuth in real-time using javascript, otherwise you will be requesting tokens from Twitter OAuth on every page load.  (and sometimes that will slow down your whole site.  Instead use something like onClick=”getTokens()”)

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.

Extras

I find that you will need to use a lot of Javascript Regex to process twitter tweets and whatnot, here’s some good guides for that.

Javascript Regex – This could work well for matching/replacing strings.  SitePoint also has a great guide on Javascript Regex

How to Back Up Your Tweets on Google Calendar!

December 6th, 2009

Twistory, is a new Twitter-app site that lets you back-up your valuable tweets on Google Calendar through Google API.  It’s simple to use and all you have to do is enter your Twitter username to get started.  Of course, if you use your Google Calendar for other purposes, we suggest you to make a new Twitter-backup account for Google Calendar so it stays separate.

I find this the best way to back-up your tweets since Twitter itself doesn’t offer any kind of backups.

Best of all, it’s free so you can lose!

Try out Twistory here

Twitter Hack – Twitter Watches Notifies you of Trending Topics!

September 11th, 2009

For those of you twitter addicts out there who need to know what’s trending on Twitter, there’s a cool Twitter Hack that will update the latest trending topics on a small LCD screen.  This isn’t that hard to implement it looks like, check it out here.

The #twatch connects directly to Twitter and scrolls the latest trending topics and related tweets on an LCD screen. It’s a stand-alone network appliance that stays updated without a PC. It was awesome to watch #iranelection, Michael Jackson, and other historic events scroll by while we developed the #twatch.

twitter hac

Twitter #hashtags Trend Tracking – #hashtags!

April 25th, 2009

#hashtags is another cool Twitter Trend tracking app that lets you track and graph your favorite hashtags. (Hashtags are any words that begin with the pound(#) symbol)

This would be very useful for tracking which hashtags Twitters have been using the most in the last month or so.

You can also subscribe to your favorite hashtag trends via RSS, another cool feature for tracking your online brand.

hashtags

Geo-Location Twitter Trend Tracking – Monitter!

April 25th, 2009

monitter

Monitter is another really cool Twitter Trend tracking tool that lets you only track a specified location such as 10 miles within San Francisco.

I find this very helpful in finding other new Twitters that might live close to me.

For example, if I am a local plumber, I might want to utilize this tool to network with all the plumbers within 25 mile range of San Francisco.

Long Term Twitter Trend Tracking – Twopular!

April 25th, 2009

Twopular is another cool Twitter Trend tracking site that let’s you see which terms have been popular on Twitter in the last 2 hours, 8 hours, 24 hours, week, month, and total-ever.  I find Twopular very helpful in analyzing what has happened in the past.  For example, in the last 30 days, we can see that Easter, Earth Hour, and Oprah were pretty darn popular.

Twopular started as a pure “let’s surf a bit on the twitter wave” project. And actually, this status hasn’t really changed yet and I am still not sure what’s the real use of it. Maybe its all about amusing people by listing them as top trendsetter – not too bad. In any case for now I will keep the elephant running, hope he makes some friends out there and he will let me know one day where he wants to go.

twopoular

Twitter Trend Tracking – Twist

April 25th, 2009

Twist is another great app for tracking Twitter trends via friendly graphs that will sorta tell you when Twitters are twittering about a certain topic the most during a period of 7 days or 30 days.

I personally found that Twist is great for tracking “major” Twitter trends, it’s not too helpful if you run a small-business or you need detailed graphs on your niche brand.

This is a great way to predict which Twitter trends will become popular in the next week so I think it will be very useful especially on holidays when people might tend to buy stuff for their loved ones. (Internet Marketing tip)

twist

Twitter Hack – How to Supersize Your Firefox with GreaseMonkey Twitter Script – Troys!

April 25th, 2009

Here’s a really neat and helpful Firefox GreaseMonkey script that will allow you to enjoy the web version of Twitter more just like Twhirl or TweetDeck, it’s Troys Twitter Script.

Aside from being able to do most tedius things like RT faster, the Troys script allows you to follow your friends’ tweets closer with functionalities like name expansion, URL expansion, searchbox, and a whole lot more.

If you like to twitter via the web and Firefox, I highly suggest you give Troys Twitter Script a try.

Troy’s Twitter script, in our opinion, is crazy awesome. If you find yourself in a memory crunch and prefer not to use a standalone Twitter application, and use Firefox, this script is a must-have. In fact, it’s too bad that Greasemonkey scripts really only work well in Firefox, because it sure would be great to have all these features in every browser out there. To that end, you can try using Greasemetal (covered here) for Chrome, or GreaseKit for Safari on Mac OSX.

via readwriteweb

troys

Twitter iPhone App – TweetStack!

April 11th, 2009

For those of you twittering on an iPhone or iPod Touch, you might be interested to learn that there’s a new application you can use for speeding up relies, DMs, RTs, and more, it’s called TweetStack.

TweetStack also lets you import your TweetDeck settings, you can see how to do that here.

tweetstack

According to Mashable, the TweetStack can do other cool stuff like geo-tagging your photos:

TweetStack lacks the beautiful and sleek design of Tweetie, but once you notice that you can create stacks (ie. groups) based on TwitPic (TwitPic reviews) tags, your current location, Twitter friends, and any search term that strikes your fancy, we think you’ll be impressed. Now throw in the fact that tapping a user’s avatar gives you the option to view that user’s profile, create a group, or add the user to an existing group. Oh, and tapping a tweet itself will let you send a reply or dm, retweet it, or add it as a favorite.

via mashable