在linkedin API中的授权代码中出现错误

时间:2018-06-21 09:06:49

标签: python api linkedin

我已经尝试过了,但是它给出了错误: 从linkedin导入linkedin

API_KEY = '8xxxxxxxxxx'``
API_SECRET = '0Rxxxxxxxxxxxxxx'
RETURN_URL = 'http://localhost:8000'

authentication = linkedin.LinkedInAuthentication(API_KEY, API_SECRET, 
RETURN_URL, linkedin.PERMISSIONS.enums.values())
print (authentication.authorization_url)  
application = linkedin.LinkedInApplication(authentication)

我通过此打印命令获取的URL显示错误。 此图片有误:https://drive.google.com/open?id=1n81Jg4hXITzIraOLpAENUeYpovaHPSfa

1 个答案:

答案 0 :(得分:0)

您只需要传递您在linkedin开发人员控制台中选择的那些权限。尝试做:

PERMISSIONS = ['r_basicprofile', 'r_emailaddress'] 
authentication = linkedin.LinkedInAuthentication(API_KEY, API_SECRET, 
RETURN_URL, PERMISSIONS)
...

print authentication.authorization_url ## open this in browser

一旦授予对应用程序的访问权限,您将被重定向到为code查询参数提供的 RETURN_URL ,例如:

  

http://localhost:8000/?code=SDFKSDiodf8ayfjkdf45 ....

授权代码是上面url中 code 参数的值,因此要获取访问令牌,您可以执行

authentication.authorization_code = '<value-of-code-param-in-url>'
accessToken = authentication.get_access_token()