OAuth PHP Library with Example

5,270 views
Skip to first unread message

lucasec

unread,
Jul 25, 2011, 10:10:15 AM7/25/11
to tumbl...@googlegroups.com
Attached is some very simple, well commented example code.  It also contains a modified version of Abraham's TwitterOAuth library adapted to support the new Tumblr API.

Hopefully this will help some of you who are struggling with getting OAuth working.
TumblrOAuth_example.zip

lucasec

unread,
Jul 25, 2011, 10:37:25 AM7/25/11
to tumbl...@googlegroups.com
.. and here's an example of using this library with xAuth.

Theoretically, it should work just fine.  However, I can't verify that it works as my app does not have xAuth permissions nor do I need it.

Also, keep in mind that xAuth and XAuth are not the same thing.  When looking for documentation, look for xAuth, not XAuth.  Twitter has some nice documentation on xAuth: https://dev.twitter.com/docs/oauth/xauth.
TumblrxAuth_example.zip

Lamoni

unread,
Aug 11, 2011, 8:34:20 AM8/11/11
to Tumblr API Discussion
Thanks for this. Worked perfectly (aside from not getting responses
with ->post() when type="video", but I don't think that's fault with
the code as it works perfectly with type="photo" and type="text")
>  TumblrOAuth_example.zip
> 16KViewDownload

Lucas Christian

unread,
Aug 11, 2011, 5:36:42 PM8/11/11
to tumbl...@googlegroups.com
Glad it was helpful :).  I haven't tried video posts, but it appears everyone is having trouble with those.

Arvin

unread,
Aug 14, 2011, 12:19:05 PM8/14/11
to tumbl...@googlegroups.com
Is it working for creating photoset posts?

Lucas Christian

unread,
Aug 14, 2011, 12:44:40 PM8/14/11
to tumbl...@googlegroups.com
The library should work on any API call.  The reason we mentioned video posts was because people are having trouble with them no matter what library they use.

Hunter Sherman

unread,
Oct 24, 2011, 4:52:11 PM10/24/11
to tumbl...@googlegroups.com
I know it's been awhile since this API was posted, is there a newer way to connect to tumblr? So far this api is working for me only about 10% of the time, the rest of the time it hangs for a long time and then redirects the user to their tumblr dashboard instead of the authorization page. I have tracked it down to the http() function wherein $response = curl_exec($ci); returns false when it fails. Has the api changed?

I am using the nearly identical API to connect to twitter with no problems.

Thank you!

Kyle Wanamaker

unread,
Oct 24, 2011, 4:57:29 PM10/24/11
to tumbl...@googlegroups.com
Hunter,

Can you provide a link to the code you're actually using?

-Kyle

Hunter Sherman

unread,
Oct 24, 2011, 5:16:33 PM10/24/11
to tumbl...@googlegroups.com
Unfortunately I can't since it's on a private dev server, however I can furnish any piece of the code you may want to look at.

I am using the nearly identical library this one was based on to connect to twitter with no problems.

Luckily it does seem to be working SOMETIMES, so I have been able to dump out everything and compare the two cases.

I have tracked it down to the function http($url, $method, $postfields = NULL), more specifically $response = curl_exec($ci);  which returns false every time I fail to connect, despite all applicable variables being correctly set.

As a side note, I am using the Amazon EC2 service and I noted another commenter having issues from Amazon, is this a known issue?

Thank you!

Jordan Meyer

unread,
Oct 25, 2011, 1:23:33 AM10/25/11
to tumbl...@googlegroups.com
Thank you SOOOOO much! This is exactly what I needed! I'm really new to web design and am kinda just winging it and learning everything as I go... Sink or swim! This was a big help!

Cal

unread,
Sep 11, 2012, 8:01:46 AM9/11/12
to tumbl...@googlegroups.com, lu...@lucasec.com
I'm receiving http 400 for all calls using the xAuth example, has anyone been able to get it working?

Jeff P

unread,
Sep 28, 2012, 10:11:51 AM9/28/12
to tumbl...@googlegroups.com, lu...@lucasec.com
For some reason I can't get rid of http://www.tumblr.com/oauth/ infront of my callback url. What is causing this?

theumall com

unread,
Sep 29, 2012, 11:15:33 AM9/29/12
to tumbl...@googlegroups.com, lu...@lucasec.com
I can use an access token to access http://api.tumblr.com/v2/user/info 
and get info back but if I use the same token with 
http://api.tumblr.com/v2/blog/blah.tumblr.com/post, i get back a 401 
from the server.  What am I missing?  I'm using the scribe oauth API 
for both calls.  can you help me?

在 2011年7月25日星期一UTC+8下午10时10分15秒,lucasec写道:

Lucas Christian

unread,
Sep 29, 2012, 11:46:31 AM9/29/12
to tumbl...@googlegroups.com, lu...@lucasec.com
Did you specify the "Default Callback URL" when you registered your OAuth app?

Lucas Christian

unread,
Sep 29, 2012, 12:04:02 PM9/29/12
to tumbl...@googlegroups.com, lu...@lucasec.com
Two ideas:

(1) Is the user who's access token you have a member of the blog you're trying to post to?  Obvious, yes, but I've made such mistakes before.

(2) I haven't worked with tumblr in a bit, but twitter has a parameter titles "x_auth_access_type"  which can be set to read (read-only) or write (read and write).  I don't recall if tumblr implements that or not, but if they do, make sure you get an access token for write access.

(3) One other possibility I should mention.  I use HostGator for my main site and they have security rules that cause any scripts that you pass a URL to to return a 401.  By default if I called a script on my server with a URL in a parameter, it would not even run.  If you're not familiar with your server environment and you use URLs in query parameters, this is worth checking on.

theumall com

unread,
Sep 29, 2012, 11:04:29 PM9/29/12
to tumbl...@googlegroups.com, lu...@lucasec.com

I use lucasec's lib : TumblrOAuth_example.zip

this is my code:

and this is the result:

$tum_oauth->get('http://api.tumblr.com/v2/user/info');It's result ok.
but $tum_oauth->get('http://api.tumblr.com/v2/blog/merpherl.tumblr.com/info'); get 401  Not Authorized 


在 2012年9月30日星期日UTC+8上午12时04分02秒,Lucas Christian写道:

Lucas Christian

unread,
Sep 30, 2012, 12:18:33 AM9/30/12
to tumbl...@googlegroups.com, lu...@lucasec.com
Oh.. I'm dumb.  I checked Tumblr's documentation for /blog/info and it is not an OAuth call.  Therefore you don't need to use the OAuth library for that call.  The URL structure should be http://api.tumblr.com/v2/blog/{base-hostname}/info?api_key={Your OAuth Consumer Key}.

Lucas Christian

unread,
Sep 30, 2012, 12:24:21 AM9/30/12
to tumbl...@googlegroups.com, lu...@lucasec.com
Also, the /api/post method requires a POST request, not a GET request.  So make sure you use $tum_oauth->post('http://api.tumblr.com/v2/blog/blah.tumblr.com/post', [parameters]);

theumall com

unread,
Sep 30, 2012, 12:32:46 AM9/30/12
to tumbl...@googlegroups.com, lu...@lucasec.com
Oh,thank you very much,You are right!

在 2012年9月30日星期日UTC+8下午12时18分33秒,Lucas Christian写道:

MuZa

unread,
Oct 1, 2012, 4:23:42 AM10/1/12
to tumbl...@googlegroups.com, lu...@lucasec.com
Thank's a lot for the example. 

But I have some strange issue^

After posting a photo - the message is repeated several times. If I post several photos in a row, then the whole set is repeated. I can not understand what's the reason of this issue.
Reply all
Reply to author
Forward
0 new messages