通过 python 的 Linkedin 401 错误
Linkedin 401 Error via python
尝试使用 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()
大多数旧的 linkedin APIs,包括您尝试使用的人 API,已经过折旧并仅限于预先批准的开发人员 - 您现在需要他们的发展计划的一部分(仅限于他们积极合作的极少数公司)。
参见:https://developer-programs.linkedin.com/documents/people-search-api
People Search API is a part of our Vetted API Access Program. You must apply here and get LinkedIn's approval before using this API.
另请参阅:https://developer.linkedin.com/blog/posts/2015/developer-program-changes
Starting on May 12, 2015, we will be limiting the open APIs to only
support the following uses:
- Allowing members to represent their professional identity via their
LinkedIn profile using our Profile API.
- Enabling members to post
certifications directly to their LinkedIn profile with our Add to
Profile tools.
- Enabling members to share professional content to their
LinkedIn network from across the Web leveraging our Share API.
- Enabling companies to share professional content to LinkedIn with our
Company API.
这与您收到的错误代码一致 - 401 - Unauthorized: Access is denied due to invalid credentials.
- 如果您不是他们的开发人员计划的成员,您没有访问它的有效凭据。
尝试使用 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()
大多数旧的 linkedin APIs,包括您尝试使用的人 API,已经过折旧并仅限于预先批准的开发人员 - 您现在需要他们的发展计划的一部分(仅限于他们积极合作的极少数公司)。
参见:https://developer-programs.linkedin.com/documents/people-search-api
People Search API is a part of our Vetted API Access Program. You must apply here and get LinkedIn's approval before using this API.
另请参阅:https://developer.linkedin.com/blog/posts/2015/developer-program-changes
Starting on May 12, 2015, we will be limiting the open APIs to only support the following uses:
- Allowing members to represent their professional identity via their LinkedIn profile using our Profile API.
- Enabling members to post certifications directly to their LinkedIn profile with our Add to Profile tools.
- Enabling members to share professional content to their LinkedIn network from across the Web leveraging our Share API.
- Enabling companies to share professional content to LinkedIn with our Company API.
这与您收到的错误代码一致 - 401 - Unauthorized: Access is denied due to invalid credentials.
- 如果您不是他们的开发人员计划的成员,您没有访问它的有效凭据。