Python 中的 Identi.ca Oauth
我正在尝试在 Identi.ca 上完成 Oauth 身份验证。基本上,我尝试使用适用于 Twitter 的相同代码,但是,当然,更改了 url。由于 HTTP 错误 400:错误请求,我什至无法获取请求令牌,如下所示。我真的很想知道我做错了什么,或者与 Twitter 的做法有何不同。到目前为止我所拥有的是:
from oauth import oauth
import urllib2
class IdenticaOauth:
def __init__(self):
self.request_token_url = 'https://identi.ca/api/oauth/request_token'
self.access_token_url = 'https://identi.ca/api/oauth/access_token'
self.authorize_url = 'https://identi.ca/api/oauth/authorize'
self.consumer_key = '8024d4db70d9e49d22728f25b4c1458b'
self.consumer_secret = '4eb762cfe3c0a55950375dad795cf20e'
self.consumer = oauth.OAuthConsumer(self.consumer_key, self.consumer_secret)
self.signature_method = oauth.OAuthSignatureMethod_HMAC_SHA1()
def get_unauthorized_request_token(self):
oauth_request = oauth.OAuthRequest.from_consumer_and_token(self.consumer, http_url = self.request_token_url)
oauth_request.sign_request(self.signature_method, self.consumer, None)
url = oauth_request.to_url()
response = self.get(url)
token = oauth.OAuthToken.from_string(response)
return token
def get(self, url):
request = urllib2.Request(url)
# urllib2.HTTPError: HTTP Error 400: Bad Request
response = urllib2.urlopen(request)
return response.read()
identica_oauth = IdenticaOauth()
request_token = identica_oauth.get_unauthorized_request_token()
I am trying to accomplish the Oauth authentication on Identi.ca. Basically, I am trying to use the very same code that works for Twitter, but, of course, changing the urls. I am not even being able to get the request token, because of a HTTP Error 400: Bad Request, as shown bellow. I really would like to know what I am doing wrong, or what differs from the Twitter way of doing it. What I have so far is:
from oauth import oauth
import urllib2
class IdenticaOauth:
def __init__(self):
self.request_token_url = 'https://identi.ca/api/oauth/request_token'
self.access_token_url = 'https://identi.ca/api/oauth/access_token'
self.authorize_url = 'https://identi.ca/api/oauth/authorize'
self.consumer_key = '8024d4db70d9e49d22728f25b4c1458b'
self.consumer_secret = '4eb762cfe3c0a55950375dad795cf20e'
self.consumer = oauth.OAuthConsumer(self.consumer_key, self.consumer_secret)
self.signature_method = oauth.OAuthSignatureMethod_HMAC_SHA1()
def get_unauthorized_request_token(self):
oauth_request = oauth.OAuthRequest.from_consumer_and_token(self.consumer, http_url = self.request_token_url)
oauth_request.sign_request(self.signature_method, self.consumer, None)
url = oauth_request.to_url()
response = self.get(url)
token = oauth.OAuthToken.from_string(response)
return token
def get(self, url):
request = urllib2.Request(url)
# urllib2.HTTPError: HTTP Error 400: Bad Request
response = urllib2.urlopen(request)
return response.read()
identica_oauth = IdenticaOauth()
request_token = identica_oauth.get_unauthorized_request_token()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论