使用python-oauth2签署请求

时间:2012-03-26 15:18:23

标签: python oauth oauth-2.0

python-oauth2的Github页面提供了有关使用req = oauth.Request(...)创建签名请求的说明,该请求返回可以签名的字典。但是我该如何实际发送这些请求?

2 个答案:

答案 0 :(得分:4)

只需在最后添加此行:

rs = urllib2.urlopen(req.to_url())

req是您的请求对象。

答案 1 :(得分:1)

查看自述文件中的下一步。

使用客户端

import oauth2 as oauth

# Create your consumer with the proper key/secret.
consumer = oauth.Consumer(key="your-twitter-consumer-key", 
    secret="your-twitter-consumer-secret")

# Request token URL for Twitter.
request_token_url = "http://twitter.com/oauth/request_token"

# Create our client.
client = oauth.Client(consumer)

# The OAuth Client request works just like httplib2 for the most part.
resp, content = client.request(request_token_url, "GET")
print resp
print content