Search code examples
linkedin-api

Migrate LinkedIn to API v2


I'm using LinkedIn API v1, and saw the announcement:

All developers need to migrate their apps to our newest APIs and OAuth 2.0 by March 1, 2019.

I implemented the new Oauth2 Flow (it's basically the same, only changed the endpoint and the permission r_basicprofile to r_liteprofile) and it worked and returned the code that I use in the retrieve the access token.

After I get the access token, I make one call to return the user's firstName, lastName and id, and another to get the email (before it was only 1 request, but it's ok).

Here I saw that using the Authorization header it returned an error that said that I had not informed the access token, but if I put the access token in the paramenter oauth2_access_token I can make requests successfully.

In their docs (https://learn.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin?context=linkedin/consumer/context) they don't say where to put the access token, and in the Oauth2 flow docs (https://learn.microsoft.com/en-us/linkedin/shared/authentication/authorization-code-flow?context=linkedin/consumer/context) it uses the Authorization header with the v1 API. But, in any case, it worked using the parameter in the URL.

In v1 I'm doing:

After Oauth2 authorization:

URL: https://api.linkedin.com/v1/people/~?oauth2_access_token={{accessToken}}&format=json

After authorization using the Javascript SDK:

URL: https://api.linkedin.com/v1/people/~
Header: oauth_token={{accessToken}}

After authorization using the Mobile SDK (Android):

URL: https://api.linkedin.com/v1/people/~
Header: Authorization=Bearer {{accessToken}}
Header: x-li-src=msdk
Header: x-li-format=json

It's a bit chaotic, because each one is done in a different way, but I wasn't able to make the v1 API work in a general way for the 3 cases described above. It worked, nonetheless.

But now, how to get the user data using the v2 API?

For now I only achieved it with the Oauth2 Flow:

URL: https://api.linkedin.com/v2/me?projection=(...)&oauth2_access_token={{accessToken}}

(From what I saw other people posting, they where using the Authorization Header instead of the oauth2_access_token parameter, and I wanted to use the header, but was only able to make it work with the parameter. If anyone know how to make it work with the header instead I would be grateful).

In any case, my main question is:

How to make the migration from v1 to v2 and make it work in the same way it is now with v1? (using the token received from the frontend and also from the mobile app and retrieve the user information from that token in the back-end, like in the 3 cases I posted above using the v1 API, of which I was able to implement only the 1st, using the Oauth2 flow).


Solution

  • Unfortunately, it appears that the mobile and javascript SDKs have been deprecated. See here: https://engineering.linkedin.com/blog/2018/12/developer-program-updates

    SDKs: Our JavaScript and Mobile Software Development Kits (SDKs) will stop working. Developers will need to migrate to using OAuth 2.0 directly from their apps.

    To the best that I can tell, since the OAuth flow is available in the browser only, you'll now need to kick to web to do auth on mobile.