Linkedin OAuth访问令牌不起作用

时间:2018-08-05 04:15:26

标签: python oauth oauth-2.0 linkedin-api

我正在尝试使用linkedin创建一个简单的登录,但是我所做的一切都没有用。 This是我离开的原始线程。

到目前为止,它可以让我登录,但重定向到的URL必须关闭。

from requests_oauthlib import OAuth2Session
from requests_oauthlib.compliance_fixes 
import linkedin_compliance_fix

# In case the `redirect_url` does not implement https     
import os                                                   
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1' 

# Credentials you get from registering a new application
client_id='client here',
client_secret='client secret'
redirect_url = 'https://127.0.0.1'

# OAuth endpoints given in the LinkedIn API documentation (check for updates)
authorization_base_url = 'https://www.linkedin.com/oauth/v2/authorization'
token_url = 'https://www.linkedin.com/oauth/v2/accessToken'

# Authorized Redirect URL (from LinkedIn config)
linkedin = OAuth2Session(client_id, redirect_uri=redirect_url)
linkedin = linkedin_compliance_fix(linkedin)

# Redirect user to LinkedIn for authorization
authorization_url, state = linkedin.authorization_url(authorization_base_url)
print('Please go here and authorize,', authorization_url)

# Get the authorization verifier code from the callback url
redirect_response = input('Paste the full redirect URL here:')

# Fetch the access token
linkedin.fetch_token(token_url, client_secret=client_secret,

    authorization_response=redirect_response)

# Fetch a protected resource, i.e. user profile
r = linkedin.get('https://api.linkedin.com/v1/people/~')
print(r.content)

这是我不断遇到的错误。

  

回溯(最近通话最近):     在第30行中输入文件“ auth3.py”       Authorization_response = redirect_response)     文件“ /anaconda3/lib/python3.6/site-packages/requests_oauthlib/oauth2_session.py”,第244行,位于fetch_token中       self._client.parse_request_body_response(r.text,scope = self.scope)     在parse_request_body_response中的第411行,文件“ /anaconda3/lib/python3.6/site-packages/oauthlib/oauth2/rfc6749/clients/base.py”       self.token = parse_token_response(body,scope = scope)     在parse_token_response中,文件“ /anaconda3/lib/python3.6/site-packages/oauthlib/oauth2/rfc6749/parameters.py”,行379       validate_token_parameters(参数)     在validate_token_parameters的第389行中,文件“ /anaconda3/lib/python3.6/site-packages/oauthlib/oauth2/rfc6749/parameters.py”       引发MissingTokenError(description =“缺少访问令牌参数。”)   oauthlib.oauth2.rfc6749.errors.MissingTokenError:(missing_token)缺少访问令牌参数。

任何建议都会有所帮助。

0 个答案:

没有答案