开发者

Tumblr API Blog methods return 401 "Not Authorized", but User methods works perfect

So, there is a code that uses xAuth authentication to call tumblr API methods:

import urllib
import urlparse
import oauth2 as oauth

consumer_key     = "..."
consumer_secret  = "..."

consumer = oauth.Consumer(consumer_key, consumer_secret)
client = oauth.Client(consumer)

resp, content = client.request('https://www.tumblr.com/oauth/access_token', "POST", urllib.urlencode({
    'x_auth_mode': 'client_auth',
    'x_auth_username': '...@yandex.ru',
    'x_auth_password': '...'
}))

token = dict(urlparse.parse_qsl(content))
print token

token = oauth.Token(token['oauth_token'], token['oauth_token_secret'])
client =开发者_C百科 oauth.Client(consumer, token)

response, data = client.request('http://api.tumblr.com/v2/blog/good.tumblr.com/followers', method='GET') 
print data

It works perfect with User methods from tumblr API that require OAuth authentication. But it fails when i try to call any Blog method with OAuth authentication (/followers for example):

{"meta":{"status":401,"msg":"Not Authorized"},"response":[]}

Except one thing. If i use my blog name as {base-hostname} parameter it works without any errors. Weird. How is that possible? Is something wrong with the code?


Well that is because your OAuth access token grants you access to your blogs. OAuth can't give you permission to access Blog methods that you do not own because then you could post to them.


When you make POST request the enctype must be "multipart/form-data".

I had the same problem with Zend_Oauth (php), but is resolved now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜