Python Twitter API OAuth找不到';授权url';
我正在编写一个使用Twitter API获取用户状态、关注者数量等的代码。我需要编写一个脚本,打开浏览器,要求用户登录,并让我从他们那里获得身份验证Python Twitter API OAuth找不到';授权url';,python,authentication,twitter,python-requests,Python,Authentication,Twitter,Python Requests,我正在编写一个使用Twitter API获取用户状态、关注者数量等的代码。我需要编写一个脚本,打开浏览器,要求用户登录,并让我从他们那里获得身份验证 from requests_oauthlib import OAuth1Session import requests from requests_oauthlib import OAuth1 from urlparse import parse_qs client_key = "keykeykeykey" client_secret = "ke
from requests_oauthlib import OAuth1Session
import requests
from requests_oauthlib import OAuth1
from urlparse import parse_qs
client_key = "keykeykeykey"
client_secret = "keykeykeykeykey"
request_token_url = 'https://api.twitter.com/oauth/request_token'
oauth = OAuth1Session(client_key, client_secret=client_secret)
fetch_response = oauth.fetch_request_token(request_token_url)
#print(fetch_response)
resource_owner_key = fetch_response.get('oauth_token')
resource_owner_secret = fetch_response.get('oauth_token_secret')
oauth = OAuth1(client_key, client_secret=client_secret)
r = requests.post(url=request_token_url, auth=oauth)
#print(r.content)
credentials = parse_qs(r.content)
resource_owner_key = credentials.get('oauth_token')[0]
resource_owner_secret = credentials.get('oauth_token_secret')[0]
base_authorization_url = 'https://api.twitter.com/oauth/authorize'
authorization_url = oauth.authorization_url(base_authorization_url)
print 'Please go here and authorize,', authorization_url
redirect_response = raw_input('Paste the full redirect URL here: ')
oauth_response = oauth.parse_authorization_response(redirect_response)
#print(oauth_response)
verifier = oauth_response.get('oauth_verifier')
authorize_url = base_authorization_url + '?oauth_token='
authorize_url = authorize_url + resource_owner_key
print 'Please go here and authorize,', authorize_url
verifier = raw_input('Please input the verifier')
我从互联网上找到了此类示例,但它给出了一个错误,如:
AttributeError: 'OAuth1' object has no attribute 'authorization_url'
我已经检查了会话信息,实际上这里有授权url:
看起来您使用oauth变量作为OauthSession对象和Oauth1对象
oauth = OAuth1Session(client_key, client_secret=client_secret)
oauth = OAuth1(client_key, client_secret=client_secret)
如果您将其用作会话对象,它应该可以工作身份验证\u url与授权\u url不相同?很抱歉,我拼错并编辑了它:)