**Note** Twitter has switchted their entire interface to use OAUTH and this class no longer works (I should probably change the title hahaha). I will post an oauth connection tutorial in the near future, so make sure to subscribe to my RSS feed for all of the sweet sweets updates!
Cheers!
So, I started writing a Twitter API Programming series last week… Here is part 1. I have found that there is not much else to teach when it comes to interfacing with Twitter. Basically, we just need to implement all of the Twitter functions.
I have taken it upon myself to create a fully functional Twitter API PHP class. It has every Twitter function you will ever need (less the direct messages). I have also fully documented it with comments directly from the Twitter API so that the functions are easy to understand. Here is how you would use the class. The first parameter of every function is the return type. For Twitter it can be either xml, json, or rss for some functions.
include("Twitter.class.php"); $twitter = new Twitter(); $twitter->username = "twitteruser"; $twitter->password = "twitterpass"; // Show public timeline echo $twitter->public_timeline(); // Update your status echo $twitter->update('xml','This PHP class is flippin sweet!'); // Start following a user echo $twitter->create('xml','brandontreb');
These are just 3 of the functions implemented in this class. The full function list includes:
- public_timeline
- friends_timeline
- user_timeline
- update
- replies
- friends
- followers
- show
- create
- destroy
- exists
All of these functions are fully documented and simple to use. You can also check out Twitter’s API here (but you shouldn’t need to).
So, now you can fully integrate Twitter into any PHP application you create!
Download The PHP Twitter Class here Twitter.class.php
Also, make sure you subscribe to my RSS feed. More great programming tutorial to come.
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!


Hey Brandon, i think you are an fake, since i saw your
lines
foreach($timeline->status as $status) {
echo ‘screenname.”\”>”.$timeline->name.”".$timeline->text.”";
// end foreach loop
}
which should be (as you call all $status) $status->name and $status->text..
But most of all what i dont like is that “your” class is exactly the same as David Billingham’s
http://twitter.slawcup.com/twitter.class.phps
Its not neat!
I use this class and all is ok, but i have a little problem with the function $twiterra = $twitter->friends_timeline(‘xml’); error: 400
Yeah, I agree with Quirilles. This class is exactly like David Billingham’s with more comments and a format argument. And it’s obviously not tested. The least you could do is acknowledge the original author.
Twitter is really a good way in keeping yourself updated with the day to day activities of your friends and families members. I update my Twitter and personal blog daily.
bonjour
je veux utiliser cet class,mais je sais pas afficher la valeur de retour de la fonction ‘getfollowers’,aider mois svp
twitter has api’s and this looks like an api php class. the internet partly consists of apis. interesting.
how can i use twitter api in my new php project
Mmm…. it look good. I’ll trying in my new php project. Any demo to share please?
Doesn’t work for me. Next.
What’s the issue you are having?
This use to work, it seems to have stopped recently. I’m not sure why.
I believe that the “oauth” authentication method is now required by twitter. Mine quit working yesterday, and now I’m trying to figure it out too. This page explains: http://dev.twitter.com/pages/oauth_faq
Your code needs some change to incorporate OAuth in. See more info here:
http://blog.twitter.com/2010/08/twitter-applications-and-oauth.html
Thanks.