LinkedIn API: How to refresh access tokens from a

2019-08-03 16:57发布

问题:

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.

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.

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

回答1:

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

The way this works is as follows:

  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.

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.

I hope this helps.