The Twitter API

I’ve been messing with the Twitter API for the first time in the last few hours, and I’ve learned a TON.  I know – I’m jumping on the bandwagon late, but oh well.  I managed to create a script to retweet “stuff” based on the search functionality and I made a script to automatically follow people that post specific things.  I also managed to get my account suspended in like 2 hours due to suspicious activity – whoops.  I guess you live, you learn.  Basically everything for status updates and following uses CURL, which looks a little something like this:

<?php
 $username = "<username>";
 $password = "<password>"; t t
 $message = "<message content>";
 $url = '<API URL>';
 $curl_handle = curl_init();
 curl_setopt($curl_handle, CURLOPT_URL, "$url");
 curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
 curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($curl_handle, CURLOPT_POST, 1);
 curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message");
 curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
 $buffer = curl_exec($curl_handle);
 curl_close($curl_handle);
?>

If you’re looking for more info on how to use twitter, check out this eSeries.  It’s a good resource.

So, have questions?  Let me know.  I’m hoping to do a twitter series soon!

Saving Bandwidth with Google Ajax Libraries API

The News

I first heard about the new Google AJAX Libraries API from Jeremy Schoemaker’s blog.  He mentions using it to reduce WordPress bandwidth, but really it can be used to reduce bandwidth in most AJAX based web development environments.

The Exciting Part

I persoanlly use prototype the most, and I’m extremely excited that I can use their libraries instead of uploading my own for each site.  I’m especially excited that calling specific version numbers is possible.  This makes upgrading a code set extremely simple, especially if you call the code version as a variable at the beginning of your code.

Realistically your javascript code is probably one of the lightest weight parts of your code, but every little bit helps, especially if you’re serving a large amount of users every month.

Optional Settings

Script Compression

I think one of the greatest optional settings for all of the scripts you can load is compression.  It’s not available for all of the APIs, but it is for most.  What it does is remove all of the whitespace from the API to reduce file size for the end user – increasing speed.  If you mix that with something like the javascript compiling on Google Chrome and you’ll have lightning fast AJAX applications.

No CSS

You can optionally remove the CSS from the scripts you’re remotly loading, which allows you to do one of three things: load the default CSS, load your own CSS, or not load the CSS at all.

Resources

WordPress.org: Google AJAX Libraries API Plugin – This plugin uses the GALA whereever possible in your WordPress installation.

Google AJAX APIs Blog – This is a great place to go if this really iterests you and you’ll be using this code regularly.  They’re always adding new scripts to the API, so if you don’t see the one you want yet, keep an eye on their blog.