Search code examples
phpapioauth-2.0linkedin-api

API calls #LinkedIn for r_basicprofile


I have read carefully the LinkedIn developer documents regarding API calls, following the documents, I was able to request the access code, exchange it with server and manage to get access token.

After that I managed to get some of the member's profile, using the access token in json format with the below code.

$api_url = 'https://api.linkedin.com/v1/people/~:(id,first-name,last-name,email-address)?format=json';
$context = stream_context_create(array(
    'http' => array(
        'header' => "Authorization: Bearer " . $accessToken
    ),
));

$result = file_get_contents($api_url, false, $context);
echo $result;

however the issue is: trying to conduct any different calls will fail, although they are as per the documents of LinkedIn and they are allowed for the r_basicprofile, but yet the error:

Warning: file_get_contents(https://api.linkedin.com/v2/people/~:(industryId~)?format=json): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden

I tried some of the following but nothing goes right

$api_url = 'https://api.linkedin.com/v2/me';
$context = stream_context_create(array(
    'http' => array(
        'header' => "Authorization: Bearer " . $accessToken
    ),
));

$result = file_get_contents($api_url, false, $context);
echo $result;

I even tried to get memeber's profile with the below GET requests, but same 403 returned.

https://api.linkedin.com/v2/people/(id:{person ID})

https://api.linkedin.com/v2/people/(id:{profileID})?projection=(id,firstName,lastName,industryId~)

Would appreciate to understand how to make those calls, and what is wrong.


Solution

  • the problem is that the V2 api requires you to get a partnership with linkedin. this means you get the 403 forbidden error.

    Partnering with LinkedIn provides you with additional API functionality & data access, increased call limits & dedicated support. Read more about our various Partner Programs and use cases and see if one is a match for your app. Applications are only accepted when we feel that they're providing value to members, developers and LinkedIn.

    source: https://developer.linkedin.com/partner-programs

    fortunatly for you there is a V1 version of the api you require.

    https://api.linkedin.com/v1/people/{ID}?format=json