我正在使用urllib和urllib2从推特获取请求令牌https://dev.twitter.com/docs/auth/implementing-sign-twitter,代码如下。任何人都可以看到,我做错了什么?我得到' urllib2.HTTPError:HTTP错误401:未经授权'
#! env python
import sys
import os
import urllib
import urllib2
import uuid
import time
import base64
import string
# 1. Obtain a request token
# 2. Redirect the user
# 3. Convert the request token to an access token
consumer_key= "xxxxxxx"
consumer_secret= "xxxxxxxxxxxxxxx"
# Request token URL: https://api.twitter.com/oauth/request_token
# Authorize URL: https://api.twitter.com/oauth/authorize
# Access token URL: https://api.twitter.com/oauth/access_token
nonce = base64.b32encode(str(uuid.uuid4().hex))
# example: MYZTMMRYMEYDQN3FMFSDIYJXGNRDCMBWG42TAMJUGVTGGMZRMFSA====
nonce = nonce.rstrip('=')
print 'Nonce', nonce
data = { 'oauth_callback' : 'http://www.gooogle.com',
'oauth_consumer_key' : 'bwKT66akiJSin30L1mGnQ',
'oauth_nonce' : nonce,
'oauth_timestamp' : int(time.time()),
'oauth_version' : "1.1"
}
url_values = urllib.urlencode(data)
url = 'https://api.twitter.com/oauth/request_token'
full= url + '?' + url_values
data = urllib2.urlopen(full)
这里必须包含所有查询参数吗?