开发者

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

开发者 https://www.devze.com 2023-04-09 18:33 出处:网络
So, there is a code that uses xAuth authentication to call tumblr API methods: import urllib import urlparse

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

精彩评论

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

关注公众号