我正在编写一个简单的python脚本,我试图使用没有LinkedIn的redirect_uri从它们的API中获得连接。我曾经使用过一些API,这些API不需要重定向url或只需要https://localhost。我拿到了consumer_key,consumer_secret,user_secret,consumer_secret。下面是我从https://github.com/ozgur/python-linkedin中使用的代码
RETURN_URL = ''
url = 'https://api.linkedin.com/v1/people/~'
# Instantiate the developer authentication class
authentication = linkedin.LinkedInDeveloperAuthentication(CONSUMER_KEY, CONSUMER_SECRET,
USER_TOKEN, USER_SECRET,
RETURN_URL, linkedin.PERMISSIONS.enums.values())
# Pass it in to the app...
application = linkedin.LinkedInApplication(authentication)
print application.get_profile() # works
print application.get_connections()我得到的错误是:
Traceback (most recent call last):
File "getContacts.py", line 20, in <module>
print application.get_connections()
File "/home/imane/Projects/prjL/env/local/lib/python2.7/site-packages/linkedin/linkedin.py", line 219, in get_connections
raise_for_error(response)
File "/home/imane/Projects/prjL/env/local/lib/python2.7/site-packages/linkedin/utils.py", line 63, in raise_for_error
raise LinkedInError(message)
linkedin.exceptions.LinkedInError: 403 Client Error: Forbidden for url: https://api.linkedin.com/v1/people/~/connections: Unknown Error这是我在这里的第一个问题,如果我没有说清楚的话,请原谅,谢谢你帮助我。
下面是我在python_oauth2中尝试过的:
import oauth2 as oauth
import requests
url = 'https://api.linkedin.com/v1/people/~'
params = {}
token = oauth.Token(key=USER_TOKEN, secret=USER_SECRET)
consumer = oauth.Consumer(key=CONSUMER_KEY, secret=CONSUMER_SECRET)
# Set our token/key parameters
params['oauth_token'] = token.key
params['oauth_consumer_key'] = consumer.key
oauth_request = oauth.Request(method="GET", url=url, parameters=params)
oauth_request.sign_request(oauth.SignatureMethod_HMAC_SHA1(), consumer, token)
signed_url = oauth_request.to_url()
response = requests.get(signed_url)发布于 2016-02-03 19:39:38
截至2015年3月,Connections调用是一个受限端点。您可能使用的示例代码/文档是在任何人都可以访问这些端点时编写的。您正在接收403响应,因为您的应用程序没有发出该请求所需的权限。
https://stackoverflow.com/questions/35183488
复制相似问题