Python中的Identi.ca Oauth

时间:2012-01-29 22:28:32

标签: python oauth identica

我正在尝试在Identi.ca上完成Oauth身份验证。基本上,我试图使用适用于Twitter的相同代码,但当然,更改网址。我甚至无法获得请求令牌,因为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()

0 个答案:

没有答案