【问题标题】:Linkedin 401 Error via python通过python的Linkedin 401错误
【发布时间】:2016-06-04 17:11:55
【问题描述】:

尝试使用 Python 访问 LinkedIn Developer API,但在调用 linkedin API 时出现 401 错误。你能帮忙吗-

Traceback (most recent call last):
  File "user_request.py", line 33, in <module>
    print app.get_profile()
  File "/Users/bchawla/anaconda/lib/python2.7/site-packages/linkedin/linkedin.py", line 179, in get_profile
    raise_for_error(response)
  File "/Users/bchawla/anaconda/lib/python2.7/site-packages/linkedin/utils.py", line 63, in raise_for_error
    raise LinkedInError(message)
linkedin.exceptions.LinkedInError: 401 Client Error: Unauthorized for url: https://api.linkedin.com/v1/people/~: Unknown Error

详细代码如下-

import oauth2 as oauth
import urlparse
from linkedin import linkedin

consumer_key           = "{Key}"
consumer_secret        = "{Secret}"
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'])

print content

request_token = dict(urlparse.parse_qsl(content))

print "    - oauth_token        = %s" % request_token['oauth_token']
print "    - oauth_token_secret = %s" % request_token['oauth_token_secret']


auth = linkedin.LinkedInDeveloperAuthentication(consumer_key, consumer_secret,
request_token['oauth_token'], request_token['oauth_token_secret'], '',
permissions=linkedin.PERMISSIONS.enums.values())

print linkedin.PERMISSIONS.enums.values()

app = linkedin.LinkedInApplication(auth)

print app.get_profile()

【问题讨论】:

    标签: python linkedin oauth2


    【解决方案1】:

    大多数旧的linkedin API,包括您尝试使用的人员API,都已被弃用并仅限于预先批准的开发人员 - 您现在需要成为他们开发计划的一部分(仅限于他们积极合作的公司很少)。

    见:https://developer-programs.linkedin.com/documents/people-search-api

    人物搜索 API 是我们经过审查的 API 访问计划的一部分。在使用此 API 之前,您必须在此处申请并获得 LinkedIn 的批准。

    另见:https://developer.linkedin.com/blog/posts/2015/developer-program-changes

    从 2015 年 5 月 12 日开始,我们将开放 API 限制为仅限 支持以下用途:

    • 允许成员通过他们的 使用我们的 Profile API 的 LinkedIn 个人资料。
    • 允许成员发帖 使用我们的 Add to 将认证直接添加到他们的 LinkedIn 个人资料中 配置文件工具。
    • 使成员能够将专业内容分享给他们的 利用我们的 Share API 来自整个网络的 LinkedIn 网络。
    • 使公司能够通过我们的 公司 API。

    这与您收到的错误代码一致 - 401 - Unauthorized: Access is denied due to invalid credentials. - 由于您不是他们的开发者计划的一部分,因此您没有有效的凭据来访问它。

    【讨论】:

      猜你喜欢
      • 2015-02-02
      • 2013-09-13
      • 1970-01-01
      • 2012-07-12
      • 1970-01-01
      • 1970-01-01
      • 2021-11-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多