【发布时间】:2019-08-02 22:22:26
【问题描述】:
我一直在使用 LinkedIn api (OAuth 2),并找到了一个示例来帮助测试它。我已按照教程进行操作,但由于某种原因,当我提供完整的重定向 URL(按照代码中的要求)时,出现错误:(invalid_request) A required parameter "client_id" is missing。我不确定我做错了什么,但如果有人有任何想法,我感谢您的反馈。
在寻找解决方案时,我发现另一个人正在为此苦苦挣扎:"client_id" is missing when authenticate with LinkedIn
这是示例中的代码:
Linkedin.py
from requests_oauthlib import OAuth2Session
from requests_oauthlib.compliance_fixes import linkedin_compliance_fix
# Credentials you get from registering a new application
client_id = SECRET
client_secret = SECRET
# OAuth endpoints given in the LinkedIn API documentation
authorization_base_url = 'https://www.linkedin.com/uas/oauth2/authorization'
token_url = 'https://www.linkedin.com/uas/oauth2/accessToken'
linkedin = OAuth2Session(client_id, redirect_uri='http://localhost:8000')
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)
示例链接:https://requests-oauthlib.readthedocs.io/en/latest/examples/linkedin.html
附加说明:我使用的教程没有日期。我只能假设 API 教程中使用的链接是正确且最新的。
【问题讨论】:
标签: python django linkedin django-allauth linkedin-api