Linkedin API SDK PHP Developers

Using PHP LinkedIn SDK to fetch Company and Profile Information via API

LinkedIn has an API that makes it possible to:

  1. Fetch Profile Information like name, email, and updates
  2. Fetch Company Information like name, email and updates
  3. Post to a Profile
  4. Post to a Company
  5. And more

There’s little written about a PHP implementation for the LinkedIn API. We’ll try to give the best articles and SDKs for PHP to kickstart your LinkedIn API implementation.

One important note: LinkedIn needs an access token that you’ll receive via OAuth2. It needs to be refreshed every 60 days. And this tutorial is (of course) on your own risk.

Create an app: Client ID and Secret

In order to start, you’ll need to create an app in LinkedIn Developers. You can do that here: https://www.linkedin.com/developers/apps . Make sure that you’re entering the redirect URL’s from where you’re starting the OAuth2 process, else the app won’t work.

Then you’ll receive a Client ID and Secret. Save those two.

Install the LinkedIn SDK

Install the LinkedIn SDK, we’re using this one: https://github.com/zoonman/linkedin-api-php-client. You can install it via Composer:

composer require zoonman/linkedin-api-php-client

After that, it’s installed. Then, you can use the example script here: https://github.com/zoonman/linkedin-api-php-client/blob/master/examples/index.php. You don’t need getenv, you can change these values to your client id and secret values:

$client = new Client(
    'YOUR_CLIENT_ID',
    'YOUR_CLIENT_SECRET'
);

The demo script also posts some things to your LinkedIn profile page + company page, so make sure to comment that out, so that it doesn’t happen. Then you can sign in and do your first OAuth request.

If everything works, you’ll get some profile + company info. Check your LinkedIn profile + company profile to make sure that nothing has been shared.

Saving the token

You can save the token somewhere (safely stored). And call it again. You can then modify the demo script that it initializes with the token:

// add Composer autoloader
include_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor/autoload.php';

// import client class
use LinkedIn\Client;
use LinkedIn\Scope;
use LinkedIn\AccessToken;

// instantiate the Linkedin client

$client = new Client(
    'YOUR_CLIENT_ID',
    'YOUR_CLIENT_SECRET'
);

// load token from the file
$token = 'YOUR_TOKEN';
$expires = 'EXPIRY';
// instantiate access token object from stored data
$accessToken = new AccessToken($token, $expires);

// set token for client
$client->setAccessToken($accessToken);

if (!empty($token))
{
	// Do the client magic here!
}

You can put this information in a separate file as well and run it. Then you’re good to go!

Relevant resources

  1. https://medium.com/@ellesmuse/how-to-get-a-linkedin-access-token-a53f9b62f0ce
  2. https://www.linkedin.com/developers/
  3. https://github.com/zoonman/linkedin-api-php-client

Good luck. Got any tips? Leave a comment below.

2 thoughts on “Using PHP LinkedIn SDK to fetch Company and Profile Information via API”

  1. i add these three scopes ‘r_emailaddress,r_liteprofile,w_member_social’

    only these three permission are available and i need comany data as well as user full profile data .
    so how can i add more scopes.
    thanks!

Leave a Comment

Your email address will not be published. Required fields are marked *

en_USEnglish
Scroll to Top