我想获得经过身份验证的用户个人资料数据Twitter。实际上,可以获取access_token
,但是当应用程序获取twitter_profile_detail
时会发生错误。
错误代码:
response 410
我的代码:
access_token_url = 'https://api.twitter.com/oauth/access_token'
protected_url = 'https://api.twitter.com/1/account/settings.json'
oauth_token = request.args.get('oauth_token')
oauth_verifier = request.args.get('oauth_verifier')
twitter = OAuth1Session(
client_id,
client_secret,
oauth_token,
oauth_verifier
)
response = twitter.post(
access_token_url,
params={'oauth_verifier': oauth_verifier}
)
access_token = dict(parse_qsl(response.content.decode("utf-8")))
## Success fetched
oauth = OAuth1Session(
client_id,
client_secret=client_secret,
resource_owner_key=access_token["oauth_token"],
resource_owner_secret=access_token["oauth_token_secret"]
)
response = oauth.get(protected_url)
## 410 error
user = get_or_create_user(access_token)
get_or_create_twitter_profile(user, access_token)
更新受保护的网址:
protected_url = 'https://api.twitter.com/1.1/account/verify_credentials.json'