linkedin api - python - get_connections()

时间:2016-02-03 17:13:51

标签: python-2.7 linkedin oauth2

我正在研究一个简单的python抓取脚本,我正在尝试使用他们的API从LinkedIn获取连接而没有redirect_uri。我曾经使用过一些API,不需要重定向网址或只需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)

1 个答案:

答案 0 :(得分:0)

截至2015年3月,

Connections API调用是受限制的端点。您可以使用在任何人都可以访问这些端点时编写的示例代码/文档。您收到403回复,因为您的申请合法地没有提出该请求所需的许可。