LinkedIn API:如何从控制台应用程序刷新访问令牌 [英] LinkedIn API: How to refresh access tokens from a console application

查看:81
本文介绍了LinkedIn API:如何从控制台应用程序刷新访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在LinkedIn API中,访问令牌将在60天后过期,我想在控制台应用程序中在60天之前刷新它们.我查看了此文档: https://developer.linkedin.com/Blog/tips-and-tricks-refreshing-access-token ,并且我也查看了该论坛中的许多帖子,但看来刷新流程现在对我来说仍然很清楚.

In LinkedIn API, the access tokens will be expired after 60 days, I want to refresh them in 60 days before they are expired in a console application. I viewed this document: https://developer.linkedin.com/blog/tips-and-tricks-refreshing-access-token, and I also viewed many posts in this forum, but it looks like the refresh flow is still now clear for me.

请注意: 我需要从控制台应用程序刷新访问令牌-它不是网站,它是在后端运行的工具,它没有没有Cookie ,并且无法打开网页询问用户登录.

Please note that: I need to refresh access tokens from a console application - it is not a website, it is a tool running in backend, it has no cookies and cannot open web page to ask user to login.

如果有一些更好的示例代码(不适用于网站),例如:C#或Java代码.

And if there are some sample code (not for website) that should be better, for example: C# or Java code.

推荐答案

您可以使用curl来完成此任务.无论您使用哪种编程语言,都应该有一个相关的curl库.

You can use curl to accomplish this. For whatever programming language you use, there should be a relevant curl library.

其工作方式如下:

  1. 您将POST请求发送到https://api.linkedin.com/uas/oauth/requestToken
  2. 您会收到一个请求令牌.在以下调用中,使用该令牌代替XXX:https//www.linkedin.com/uas/oauth/authenticate?oauth_token=XXX
  3. 您将收到所需的响应,其中包括您需要保存的访问令牌.它不会在接下来的60天内过期.
  1. You send a POST request to https://api.linkedin.com/uas/oauth/requestToken
  2. You receive back a request token. Use that token in place of XXX in the following call: https//www.linkedin.com/uas/oauth/authenticate?oauth_token=XXX
  3. You will receive the response you need, which includes the access token, which you need to save. It will not expire for the next 60 days.

如果您可以详细说明遇到的问题,那肯定会有所帮助.

If you could elaborate on the issues you're having, that would certainly help.

我明白你的意思了. Linkedin不允许您,也永远不会允许您这样做.访问令牌过期的原因是为了为用户添加额外的隐私保护层.如果用户不积极使用您的应用程序,Linkedin永远不会希望您访问用户数据.当然,您可能会遇到不需要采取任何措施的情况,这是唯一的缺点.因此,您需要给他们一个理由,以便在每个令牌的生存期内至少访问您的应用程序一次.

I see what you mean now. Linkedin doesn't allow you and will never allow you to do this. The reason access tokens expire is in order to add an extra layer of privacy protection for users. Linkedin would never want you to access user data if the user's aren't actively using your application. Of course, you might have a situation where no action is required on their part, that's the only drawback. Therefore, you would need to give them a reason to visit your application at least once in each token's lifetime.

我希望这会有所帮助.

这篇关于LinkedIn API:如何从控制台应用程序刷新访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆