用户身份验证linkedin -

时间:2017-12-16 19:09:42

标签: python api python-requests linkedin

我正在尝试在linkedin api中进行身份验证,以便从个人和公司资料中删除一些数据。我对developer.linkedin.com提供的OAuth2.0文档非常困惑。我不确定我是否正在使用正确的api调用访问数据点。例如,我想要了解许多用户的工作历史等等。但在我点击它之前,如何验证用户进行api调用?我使用以下芽不起作用 -

client_id ='.....'

client_secret='.....'
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='https://127.0.0.1')
linkedin = linkedin_compliance_fix(linkedin)
authorization_url, state = linkedin.authorization_url(authorization_base_url)

print 'Please go here and authorize,', authorization_url

redirect_response = raw_input('Paste the full redirect URL here:') 
#here I add https://127.0.0.1

linkedin.fetch_token(token_url, client_secret=client_secret,
    authorization_response=redirect_response)

r = linkedin.get('https://api.linkedin.com/v1/people/~')  
print r.content

我从这里开始遵循教程:https://github.com/requests/requests-oauthlib/blob/master/docs/examples/linkedin.rst

这是我在终端请求时输入 - https://127.0.0.1的消息。

python ~/linkedin.py
Please go here and authorize, https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=777m76reoggue0&redirect_uri=https%3A%2F%2F127.0.0.1&state=bo91J8MNuMTx1WQWn9nLd5kgGbZYFE
**Paste the full redirect URL here:https://127.0.0.1**
Traceback (most recent call last):
  File "~/linkedin.py", line 22, in <module>
    authorization_response=redirect_response)
  File "/anaconda/lib/python2.7/site-packages/requests_oauthlib/oauth2_session.py", line 187, in fetch_token
    state=self._state)
  File "/anaconda/lib/python2.7/site-packages/oauthlib/oauth2/rfc6749/clients/web_application.py", line 174, in parse_request_uri_response
    response = parse_authorization_code_response(uri, state=state)
  File "/anaconda/lib/python2.7/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 227, in parse_authorization_code_response
    raise MissingCodeError("Missing code parameter in response.")
oauthlib.oauth2.rfc6749.errors.MissingCodeError: (missing_code) Missing code parameter in response.

1 个答案:

答案 0 :(得分:0)

确保:

  • 您已将{{3>}作为授权重定向网址注册到您的linkedin应用
  • 您在浏览器中使用?=code参数粘贴完整的重定向网址,如下所示:

    在[19]中:redirect_response

    Out [19]:'http://127.0.0.1!'

  • 您使用HTTPS而不是HTTP

  • 粘贴该网址