1

我正在研究一个简单的 python 抓取脚本,我正在尝试使用他们的 API 从 LinkedIn 获取连接,而不使用 redirect_uri。我曾经使用过一些 API,它们不需要重定向 url 或只需要https://localhost。我得到了consumer_key、c​​onsumer_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)
4

1 回答 1

0

截至 2015 年 3 月,Connections API 调用是一个受限制的端点。您可能正在使用在任何人都可以访问这些端点时编写的示例代码/文档。您收到 403 响应是因为您的应用程序合法地没有发出该请求所需的权限。

于 2016-02-03T19:39:38.647 回答