Howdy! Thanks for coming and enjoy your stay! Take a look at the sitemap and don't forget to chirp!

The Twitter OAuth PHP Class Gets Even Better

December 14th, 2009

Or perhaps simpler?.. Together with the Twitter API itself, the TwitterOAuth PHP class (the one by Abraham Williams) is being updated too! According to GitHub the latest changeset was commited on December 3rd so yeah, I tried to take a look at what’s going on there a few days ago and was quite disapointed. Disappointed with the fact that all my previous code was broken without giving any reason.

Just like everybody else, I never read the readme or other documentation files so I dug straight into the class code and examples. Soon after I realized that the new changes were not that bad, so instead of the usual 5 lines of code, I shortened it up to only one. I stopped worrying about parsing XML or JSON, converting them to objects, and I stopped typing in the full address for Twitter API calls. Abraham did all that for us, so all we have left is:

$credentials = $oauth->get("account/verify_credentials");
if ($oauth->http_code == 200)
	echo "Hey there, {$credentials->screen_name}!";

I’m not going to publish all the new features and stuff (read about them at GitHub), but hey, this is quite sweet isn’t it? The only drawback was having to rewrite some parts of the code I wrote for the past few months (the Twitter Robots stuff), but I guess that’s partly my bad as it’s not as organized as it should be. That’s the main reason why I’m not publishing the whole code here yet, have a lot of cleaning up to do ;)

Meanwhile you may take a look at this buddy: @web2feed. I turned off the auto-replies because they were getting quite annoying, and I’ve added a couple of feeds to the big list, oh and it’s DM controlled too!

Related posts:

  1. Twitter API: PIN-based OAuth Using PHP
  2. The Importance of Using Twitter API via OAuth
  3. Twitter API: Moving From Basic Auth to OAuth
  4. Automated Serverside Tweeting Using OAuth
  5. PHP: The User Class Snippet

7 Responses to “The Twitter OAuth PHP Class Gets Even Better”

  1. Glad you like the new changes. The lack of backwards compatibility does suck but I feel the slimmed down version is worth it.

    I’ve been build a list of applications using TwitterOAuth and would like to add any you have.
    http://wiki.github.com/abraham/twitteroauth/links

    • kovshenin (@kovshenin)

      Heh, that page mentions me 4 times, thanks so much buddy! I’m working on a new and massive “Twitter for WordPress” plugin, perhaps that’ll be good enough to make it to the Projects list, right below Foller.me ;)

      Cheers!

  2. dhwanit

    Hey,

    I have been using TwitteroAuth class, one thing i am trying to do is query the REST api using the user’s access token. I am using oAuthRequest() function to fetch the user’s credential, it gives me not authorized error. However the method you used worked fine but I cannot understand why the other on didnt work. Can you please shed some light on how the actual process work??

    • Abraham Williams (@abraham)

      You should never call oAuthRequest() directly. You should use getRequestToken(), getAuthorizeURL(), getAccessToken(), get(), and post() functions.

Including pingbacks & trackbacks

  1. The Twitter OAuth PHP Class Gets Even Better | Coder Online linked here on December 14, 2009 at 5:36 pm
  2. uberVU - social comments linked here on December 15, 2009 at 4:06 am