通过python的Linkedin 401错误
试图使用Python访问LinkedIn开发人员API,但在调用LinkedIn API时出现401错误。你能帮忙吗-通过python的Linkedin 401错误,python,linkedin,oauth2,Python,Linkedin,Oauth2,试图使用Python访问LinkedIn开发人员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/linke
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
大多数旧的linkedin API,包括您正在尝试使用的people API,都被贬低,仅限于预先批准的开发人员—您现在需要成为他们开发计划的一部分(仅限于他们积极合作的一小部分公司) 见: 人员搜索API是我们经过审查的API访问程序的一部分。在使用此API之前,您必须在此申请并获得LinkedIn的批准 另见: 从2015年5月12日开始,我们将把开放API限制在 支持以下用途:
- 允许会员通过其 LinkedIn配置文件使用我们的配置文件API
- 使成员能够发布 通过我们的Add-to将认证直接添加到他们的LinkedIn个人资料中 轮廓工具
- 使成员能够将专业内容共享给他们的 LinkedIn利用我们的共享API通过网络建立网络
- 使公司能够与我们的客户共享LinkedIn的专业内容 公司API
401-未经授权:由于凭据无效,访问被拒绝。
-鉴于您不是他们开发人员程序的一部分,您没有访问该程序的有效凭据
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()