tweetPHP is a php class for interfacing with twitters API, and allows developers to fetch tweets, fetch followers and post tweets in a really simple way using php.
Connecting to the API is now a snap!
It's now really simple to connect to twitter to grab your user information, all you need to do to establish your connection is include the class.twitter.php file and type out one line of code:
<?PHPAnd thats it! You're now ready to use the class's built in functions to use twitter with your own web applications.
include "class.twitter.php";
$object = new twitter('user', 'pass');
?>
Post a tweet!
Once you've established your new connection to the API, you'll now be able to post a tweet, again this only takes a single line of code.
$object->post_tweet("Wow I'm posting with PHP");
This single line of code will send the tweet straight to twitter.
Grab your timeline!
Once you've connected to twitters API, you may not wish to send a tweet and you might want to display your twitter feed. This again only requires one line of code:
$object->fetch_tweets();But this is only the default method of fetching tweets, and the fetch_tweet function has several optional parameters that allow you to alter how many tweets to display and whether to impose a character limit. The format used for these optional parameters is as follows:
$object->fetch_tweets('No.Of Tweets', Character limit "True" or "False", character limit);
A proper example would be:
$object->fetch_tweets(10, True, 46);The code above would fetch ten tweets from your feed and limit each tweet to a maximum of 46 characters including spaces.
Grab a list of your followers!
You may be able to guess by now that to fetch a list of your friends on twitter, also takes only one aditional line of code:
$object->fetch_followers();This line of code will return a list of your friends on twitter.
Summary
So far the tweetPHP class is getting stronger by the day and is currently only 100 lines long. I aim to add more functionality to the class creating a module that will allow web application developers to implement twitter on the fly!
Tim Davies
tim@lostpixel.net