Linkedin API无效访问令牌(Python)

2024-09-28 17:21:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我只想在LinkedIn上发一篇hello world帖子

一种方法是使用selenium,但如果可能的话,我宁愿使用API。 另一种方法是使用API,此处对此进行了详细说明: https://www.jcchouinard.com/how-to-post-on-linkedin-api-with-python/

我执行代码,并从网站获取访问令牌

然后我使用访问令牌获取用户信息

从这里我可以发邮件

但是,我遇到的问题是,访问令牌可能会过期:

{
'serviceErrorCode': 65600,
'message': 'Invalid access token',
'status': 401
}

这里有一种手动获取新令牌的方法: https://pypi.org/project/python3-linkedin/ 使用此指令,当您授予对应用程序的访问权限时,将重定向到返回url,并在返回url后附加以下查询字符串:"http://localhost:8000/?code=#############################################&state=########################"

我的问题是:有没有一种方法可以在不必手动操作的情况下获取刷新的access token

(特别是LinkedIn网站表明代币有效期为2个月)


Tags: 方法httpstokenapiurlhelloworldaccess