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!
[…] See the article here: The Twitter OAuth PHP Class Gets Even Better […]
[…] This post was mentioned on Twitter by kovshenin, Abraham Williams. Abraham Williams said: Check out this blog post about switching to v2.x of @ouathlib by @kovshenin http://bit.ly/525cb0 […]
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
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!
Social comments and analytics for this post…
This post was mentioned on Twitter by abraham: Check out this blog post about switching to v2.x of @ouathlib by @kovshenin http://bit.ly/525cb0…
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??
You should never call oAuthRequest() directly. You should use getRequestToken(), getAuthorizeURL(), getAccessToken(), get(), and post() functions.
hi!
is there any way to include the email in oauth? its very odd that I have to ask for the email after they allow my app…
Including email has nothing to do with OAuth. You will have to ask Twitter to surface it in their API.
Abraham, thanks so much for being active here ;)