2
votes

recently linkedin has sent a reminder email:

Important update: All developers need to migrate to Version 2.0 of our APIs and OAuth 2.0 by March 1, 2019. Learn more

I'm using Linkedin Rest API to get user information after the authorization. The old v1 api was: https://api.linkedin.com/v1/people/~

Looking at the migration guide found here: https://docs.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/migration-faq?context=linkedin/consumer/context

this request has to be changed. I tried to make the following requests:

https://api.linkedin.com/v2/me

to get user basic info (as first_name and last_name)

and then:

https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))

to get the user email address

Unfortunately the first request always return:

{
    "serviceErrorCode": 100,
    "message": "Not enough permissions to access: GET /me",
    "status": 403
}

I have searched a lot here on stackoverflow and a lot suggest that you need to subscribe as partner to get access to v2 api

here: https://business.linkedin.com/marketing-solutions/marketing-partners/become-a-partner/marketing-developer-program

Linkedin in the migration guide says:

Does my developer application have access to the v2 API? Any developer application created through the LinkedIn Developer Portal after December 15, 2018 automatically has access to the v2 API.

What about existing developer applications? If your developer application has made a successful v1 API request since October 1, 2018, your developer application automatically has access to the v2 API.

futhermore if I ask for the emailAddress v2 API, I get the correct response... so I don't think I need to compile the form the become a partner.

What should it be the problem?

Here the full path for authentication and API calls:

1) Go to auth page to request for permissions

window.location.href = "https://www.linkedin.com/oauth/v2/authorization?response_type=code" +
        "&client_id=" + linkedin_id + "&redirect_uri=" + redirect_uri +
        "&state=" + state + "&scope=r_basicprofile+r_emailaddress"

2) Retrieve the access token

request = ("https://www.linkedin.com/oauth/v2/accessToken?grant_type=authorization_code&code=" +
                     code + "&redirect_uri=" +
                     redirect_uri + "&client_id="
                     + linkedin_id +
                     "&client_secret=" + linkedin_secret)

response = requests.get(request)

3) The access token is retrieved, we can request for user info ALWAYS 403

headers = {"Authorization": "Bearer "+token }
    get_user = requests.get('https://api.linkedin.com/v2/me', headers=headers)

4) Get user_email working

get_user_email = requests.get('https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))', headers=headers)

Thanks

3
In your step 1, change &scope=r_basicprofile+r_emailaddress into &scope=r_emailaddress+r_liteprofile - Morris
@Vic thank you, after I have add r_liteprofile as scope and add it as a Default Application Permissions in the admin Linkedin application portal, it works! Thanks - Giacomo Rocco

3 Answers

3
votes

try to use r_liteprofile instead of r_basicprofile if you only need the first name and last name

0
votes

Try this :

change in step one : &scope=r_basicprofile+r_emailaddress into &scope=r_liteprofile+r_emailaddress

call this : https://api.linkedin.com/v2/me?projection=(id,firstName,lastName,profilePicture(displayImage~:playableStreams))

Working for getting r_liteprofile information you will get firstName, lastName, profilePicture, id

0
votes

You should pass '&scope=r_basicprofile+r_emailaddress' this at time of AccessToken Request

Step 1: AccessToken Requst will be like

https://www.linkedin.com/oauth/v2/accessToken?grant_type=authorization_code&code={Your code}&redirect_uri={Yourredirect_uri}&client_id={Your client_id}&client_secret={Your client_secret }&scope=r_liteprofile+r_emailaddress

This will return you the AccessToken using which You do have to make 2 more request 1 is for Email and Profile Details

Step 2: for Email request will be like

https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))&oauth2_access_token={AccessToken You get from step 1}'

Step 3: for basic profile request will be like

https://api.linkedin.com/v2/me?projection=(id,firstName,lastName,emailAddress,profilePicture(displayImage~:playableStreams))&oauth2_access_token={AccessToken You get from step 1}'