PHP Twitter API Client

Lab Project

I’ve been having some fun with Twitter lately.

Twitter’s direct messaging feature is great for automated messaging tasks. With SMS and IM forwarding, I can receive critical updates from a server (or my coffee pot… or whatever) just about anywhere. Good times!

In need of Twitter’s services for a recent side project, I thought it would be nice to have a simple easy-to-use Twitter client that fit in with our existing libraries.

Feedback is definitely welcome. Feel free to email me at mattw@arc90.com with questions, comments or suggestions or post your comments over at the Arc90 blog.

Happy Twittering!


What is this?

The Arc90_Service_Twitter class makes requests to the Twitter API via PHP and cURL.

How Do I Use It?

To use Arc90_Service_Twitter in your PHP project, just follow these simple steps:

Download The Code From Google Code

Click on the icon below to go get the source from Google Code:


Download

The most recent download will contain source code, usage instructions, and documentation

Add the code to your PHP project

You’ll need to add the contents of the ‘lib’ folder to your include path.

Create an Arc90_Service_Twitter API client with a valid Twitter username and password

<?php
require_once('Arc90/Service/Twitter.php');
$twitter = new Arc90_Service_Twitter('username', 'password');

Arc90_Service_Twitter returns an Arc90_Service_Twitter_Response object containing the
requested data and all of the HTTP metadata recorded by cURL

Data may be requested in any format supported by Twitter (XML, JSON, and sometimes RSS and ATOM). The default type
is JSON.

<?php
require_once('Arc90/Service/Twitter.php');
$twitter = new Arc90_Service_Twitter('username', 'password');
try
{
// Gets the authenticated user's friends timeline in XML format
$response = $twitter->getFriendsTimeline('xml');
// Print the XML response
echo $response->getData() . "n";
// If Twitter returned an error (401, 503, etc), print status code
if($response->isError())
{
echo $response->http_code . "n";
}
}
catch(Arc90_Service_Twitter_Exception $e)
{
// Print the exception message (invalid parameter, etc)
print $e->getMessage();
}

Documentation

Review the complete documentation for a full list of all functions available with Arc90_Service_Twitter.

Note: Up-to-date documentation is included with each release in the ‘docs’ folder.

Licensing

This arc90 tool is licensed under a BSD license.

Discuss Arc90_Service_Twitter

You can offer feedback on Arc90_Service_Twitter at the arc90 blog.