[英]Not able to authorize the token for the LinkedIn
我正在尝试连接到LinkedIn API。 尽管给出了正确的consumer_key,但consumer_secret与LinkedIn应用程序中的相同。 我无法授权为令牌生成的链接。 当我将其粘贴到浏览器中并转到链接时,将显示一条消息,提示“糟糕,出了点问题。范围“ rw_migration”未获得您的应用程序的授权”。
请求您的帮助。 我是python和API的新手。 在Google搜索上也找不到任何帮助。
import oauth2 as oauth
import urllib
consumer_key='xxxxxxxx' #from Linkedin site
consumer_secret='xxxxxxx' #from Linkedin site
consumer=oauth.Consumer(consumer_key, consumer_secret)
client=oauth.Client(consumer)
request_token_url='https://api.linkedin.com/uas/oauth/requestToken'
resp, content=client.request(request_token_url, "POST")
if resp['status']!='200':
raise Exception("Invalid response %s." % resp['status'])
content_utf8=str(content,'utf-8') #convert binary to utf-8 string
request_token=dict(urllib.parse.parse_qsl(content_utf8))
authorize_url=request_token['xoauth_request_auth_url']
print("Go to the following link in your browser:", "\n")
print(authorize_url+'?oauth_token='+request_token['oauth_token'])
accepted='n'
while accepted.lower()=='n':
accepted=input('Have you authorized me? (y/n)') #prompt for input (y)
oauth_verifier=input('What is the PIN?') #prompt for pin
access_token_url='https://api.linkedin.com/uas/oauth/accessToken'
token=oauth.Token(request_token['oauth_token'], request_token['oauth_token_secret'])
token.set_verifier(oauth_verifier)
client = oauth.Client(consumer, token)
resp, content = client.request(access_token_url, "POST")
content8=str(content,'utf-8')
access_token = dict(urllib.parse.parse_qsl(content8))
print("Access Token:", "\n")
print("- oauth_token = "+access_token['oauth_token']+'\n')
print("- oauth_token_secret = "+access_token['oauth_token_secret'])
print("You may now access protected resources using the access tokens above.")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.