【问题标题】:python linkedin oauth2 - where is http_api.py?python linkedin oauth2 - http_api.py 在哪里?
【发布时间】:2017-05-04 05:29:53
【问题描述】:

我正试图让这个示例在 https://github.com/ozgur/python-linkedin 中运行。我用他的例子。当我运行这段代码时。我没有得到示例中提到的RETURN_URLauthorization_code。我不知道为什么,我认为这是因为我没有正确设置HTTP API example。我找不到http_api.py,当我访问http://localhost:8080 时,我收到“无法访问此站点”。

from linkedin import linkedin

API_KEY = 'wFNJekVpDCJtRPFX812pQsJee-gt0zO4X5XmG6wcfSOSlLocxodAXNMbl0_hw3Vl'
API_SECRET = 'daJDa6_8UcnGMw1yuq9TjoO_PMKukXMo8vEMo7Qv5J-G3SPgrAV0FqFCd0TNjQyG'
RETURN_URL = 'http://localhost:8000'

authentication = linkedin.LinkedInAuthentication(API_KEY, API_SECRET, RETURN_URL, linkedin.PERMISSIONS.enums.values())
# Optionally one can send custom "state" value that will be returned from OAuth server
# It can be used to track your user state or something else (it's up to you)
# Be aware that this value is sent to OAuth server AS IS - make sure to encode or hash it
#authorization.state = 'your_encoded_message'
print authentication.authorization_url  # open this url on your browser
application = linkedin.LinkedInApplication(authentication)

【问题讨论】:

  • 请从您的 LinkedIn 帐户中删除此 API 密钥和密码!它们不应该公开分享。

标签: python linkedin linkedin-api


【解决方案1】:

http_api.pyone of the examples provided in the package。这是一个 HTTP 服务器,将处理来自 LinkedIn 的 OAuth 端点的响应,因此您需要启动它才能使示例工作。

如指南中所述,您需要execute that example file 才能使服务器正常工作。请注意,您还需要提供以下环境变量:LINKEDIN_API_KEYLINKEDIN_API_SECRET

您可以通过下载 repo 并调用 LINKEDIN_API_KEY=yourkey LINKEDIN_API_SECRET=yoursecret python examples/http_api.py 来运行示例文件。请注意,您需要 Python 3.4 才能工作。

【讨论】:

  • 好的,现在当我执行第 1 步时,请访问 localhost:8080。我在浏览器中得到http://localhost:8080/code?error=invalid_scope&error_description=Your+application+has+not+been+authorized+for+the+scope+%22rw_nus%22#! ...在python中得到AssertionError: You must first get the authorization code
  • 您是否访问了您创建的片段中给出的授权 URL?
  • 是的,我向您展示的是使用创建的代码访问 URL 的结果。
  • 它确实有效,您只需要确保您授权应用程序获得您的应用程序在 LinkedIn 上所需的权限。
猜你喜欢
  • 2014-10-25
  • 2016-03-12
  • 1970-01-01
  • 2018-02-15
  • 2021-04-20
  • 2019-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多