我正在尝试对LinkedIn API进行身份验证,以使用我的LinkedIn App凭据从公司页面检索数据。
在Oauth 2.0设置下:
重定向URL: http://localhost:8000/
不能完全确定要在上面添加哪个URL。
from requests_oauthlib import OAuth2Session
from requests_oauthlib.compliance_fixes import linkedin_compliance_fix
# Credentials you get from registering a new application
client_id = '*********'
client_secret = '********'
redirect_url = 'http://localhost:8000/'
# OAuth endpoints given in the LinkedIn API documentation (you can check for the latest 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 configuration)
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)
打开URL并登录并授权客户端后,我不断收到此错误: InvalidClientIdError:(invalid_request)缺少必需的参数“ client_id”
我确定这些是用于LinkedIn的最新URL
答案 0 :(得分:0)
这有点晚了,但是我今天遇到了同样的问题。
解决方案在于传递一个标志,强制使用client_id:
linkedin.fetch_token(token_url, client_secret=client_secret, authorization_response=redirect_response, include_client_id=True)
希望对您有帮助!