PHPackages                             nhanchaukp/linkedin-api-php-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. nhanchaukp/linkedin-api-php-client

ActiveLibrary[HTTP &amp; Networking](/categories/http)

nhanchaukp/linkedin-api-php-client
==================================

LinkedIn API PHP SDK with OAuth 2.0 &amp; CSRF support. Can be used for social sign in or sharing on LinkedIn. Examples. Documentation.

0.0.19(3y ago)015MITPHPPHP &gt;=5.6

Since Aug 24Pushed 3y agoCompare

[ Source](https://github.com/nhanchaukp/linkedin-api-php-client)[ Packagist](https://packagist.org/packages/nhanchaukp/linkedin-api-php-client)[ Docs](https://github.com/nhanchaukp/linkedin-api-php-client)[ RSS](/packages/nhanchaukp-linkedin-api-php-client/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (3)Dependencies (5)Versions (20)Used By (0)

LinkedIn API Client with OAuth 2 authorization written on PHP
=============================================================

[](#linkedin-api-client-with-oauth-2-authorization-written-on-php)

[![Build Status](https://camo.githubusercontent.com/710cd04d9366ec0bbfefb01c69c423e988cf87ca51d077e42ef6367f571f68e7/68747470733a2f2f7472617669732d63692e6f72672f7a6f6f6e6d616e2f6c696e6b6564696e2d6170692d7068702d636c69656e742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/zoonman/linkedin-api-php-client) [![Code Climate](https://camo.githubusercontent.com/31670f8f3f41a93fed43a5d3d5722adb0dbc2b8f6e10c3679d8dc9356614e4aa/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f7a6f6f6e6d616e2f6c696e6b6564696e2d6170692d7068702d636c69656e742f6261646765732f6770612e737667)](https://codeclimate.com/github/zoonman/linkedin-api-php-client) [![Packagist](https://camo.githubusercontent.com/f34c06a531a5551a54a53634527a1a2c0d2f2cbd079f90f5869fb410dfb97740/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7a6f6f6e6d616e2f6c696e6b6564696e2d6170692d7068702d636c69656e742e737667)](https://packagist.org/packages/zoonman/linkedin-api-php-client) [![GitHub license](https://camo.githubusercontent.com/e5c601aaec811fb7f7575f9d47809b59c87a9ead1aae825168bedc910be71880/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7a6f6f6e6d616e2f6c696e6b6564696e2d6170692d7068702d636c69656e742e737667)](https://github.com/zoonman/linkedin-api-php-client/blob/master/LICENSE.md)

See [complete example](examples/) inside [index.php](examples/index.php) to get started.

Installation
------------

[](#installation)

You will need at least PHP 7.3. We match [officially supported](https://www.php.net/supported-versions.php) versions of PHP.

Use [composer](https://getcomposer.org/) package manager to install the lastest version of the package:

```
composer require nhanchaukp/linkedin-api-php-client
```

Or add this package as dependency to `composer.json`.

If you have never used Composer, you should start [here](http://www.phptherightway.com/#composer_and_packagist)and install composer.

Get Started
-----------

[](#get-started)

Before you will get started, play visit to [LinkedIn API Documentation](https://docs.microsoft.com/en-us/linkedin/). This will save you a lot of time and prevent some silly questions.

To start working with LinkedIn API, you will need to get application client id and secret.

Go to [LinkedIn Developers portal](https://developer.linkedin.com/)and create new application in section My Apps. Save ClientId and ClientSecret, you will use them later.

#### Bootstrapping autoloader and instantiating a client

[](#bootstrapping-autoloader-and-instantiating-a-client)

```
// ... please, add composer autoloader first
include_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';

// import client class
use LinkedIn\Client;

// instantiate the Linkedin client
$client = new Client(
    'YOUR_LINKEDIN_APP_CLIENT_ID',
    'YOUR_LINKEDIN_APP_CLIENT_SECRET'
);
```

#### Getting local redirect URL

[](#getting-local-redirect-url)

To start linking process you have to setup redirect url. You can set your own or use current one. SDK provides you a `getRedirectUrl()` helper for your convenience:

```
$redirectUrl = $client->getRedirectUrl();
```

We recommend you to have it stored during the linking session because you will need to use it when you will be getting access token.

#### Setting local redirect URL

[](#setting-local-redirect-url)

Set a custom redirect url use:

```
$client->setRedirectUrl('http://your.domain.tld/path/to/script/');
```

#### Getting LinkedIn redirect URL

[](#getting-linkedin-redirect-url)

In order of performing OAUTH 2.0 flow, you should get LinkedIn login URL. During this procedure you have to define scope of requested permissions. Use `Scope` enum class to get scope names. To get redirect url to LinkedIn, use the following approach:

```
use LinkedIn\Scope;

// define scope
$scopes = [
  Scope::READ_LITE_PROFILE,
  Scope::READ_EMAIL_ADDRESS,
  Scope::SHARE_AS_USER,
];
$loginUrl = $client->getLoginUrl($scopes); // get url on LinkedIn to start linking
```

#### Setting skip SSL when curl error code: 60

[](#setting-skip-ssl-when-curl-error-code-60)

Skip SLL defaul is skiped (true) Set a skip ssl:

```
$client->setSkipSSL(false);
```

Now you can take user to LinkedIn. You can use link or rely on Location HTTP header.

#### Getting Access Token

[](#getting-access-token)

To get access token use (don't forget to set redirect url)

```
$accessToken = $client->getAccessToken($_GET['code']);
```

This method returns object of `LinkedIn\AccessToken` class. You can store this token in the file like this:

```
file_put_contents('token.json', json_encode($accessToken));
```

This way of storing tokens is not recommended due to security concerns and used for demonstration purpose. Please, ensure that tokens are stored securely.

#### Setting Access Token

[](#setting-access-token)

You can use method `setAccessToken()` for the `LinkedIn\Client` class to set token stored as string. You have to pass instance of `LinkedIn\AccessToken` to this method.

```
use LinkedIn\AccessToken;
use LinkedIn\Client;

// instantiate the Linkedin client
$client = new Client(
    'LINKEDIN_APP_CLIENT_ID',
    'LINKEDIN_APP_CLIENT_SECRET'
);

// load token from the file
$tokenString = file_get_contents('token.json');
$tokenData = json_decode($tokenString, true);
// instantiate access token object from stored data
$accessToken = new AccessToken($tokenData['token'], $tokenData['expiresAt']);

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

#### Performing API calls

[](#performing-api-calls)

All API calls can be called through simple method:

```
$profile = $client->api(
    'ENDPOINT',
    ['parameter name' => 'its value here'],
    'HTTP method like GET for example'
);
```

There are 3 helper methods:

```
// get method
$client->get('ENDPOINT', ['param' => 'value']);

//post
$client->post('ENDPOINT', ['param' => 'value']);

// delete
$client->delete('ENDPOINT');
```

#### Examples

[](#examples)

##### Perform api call to get profile information

[](#perform-api-call-to-get-profile-information)

```
$profile = $client->get(
    'me',
    ['fields' => 'id,firstName,lastName']
);
print_r($profile);
```

##### List companies where you are an admin

[](#list-companies-where-you-are-an-admin)

```
$profile = $client->get(
    'organizations',
    ['is-company-admin' => true]
);
print_r($profile);
```

##### Share content on a personal profile

[](#share-content-on-a-personal-profile)

Make sure that image URL is available from the Internet (don't use localhost in the image url).

```
$share = $client->post(
                'ugcPosts',
                [
                    'author' => 'urn:li:person:' . $profile['id'],
                    'lifecycleState' => 'PUBLISHED',
                    'specificContent' => [
                        'com.linkedin.ugc.ShareContent' => [
                            'shareCommentary' => [
                                'text' => 'Checkout this amazing PHP SDK for LinkedIn!'
                            ],
                            'shareMediaCategory' => 'ARTICLE',
                            'media' => [
                                [
                                    'status' => 'READY',
                                    'description' => [
                                        'text' => 'OAuth 2 flow, composer Package.'
                                    ],
                                    'originalUrl' => 'https://github.com/zoonman/linkedin-api-php-client',
                                    'title' => [
                                        'text' => 'PHP Client for LinkedIn API'
                                    ]
                                ]
                            ]
                        ]
                    ],
                    'visibility' => [
                        'com.linkedin.ugc.MemberNetworkVisibility' => 'CONNECTIONS'
                    ]
                ]
            );
print_r($share);
```

##### Get Company page profile

[](#get-company-page-profile)

```
$companyId = '123'; // use id of the company where you are an admin
$companyInfo = $client->get('organizations/' . $companyId);
print_r($companyInfo);
```

##### Share content on a LinkedIn business page

[](#share-content-on-a-linkedin-business-page)

```
// set sandboxed company page to work with
// you can check updates at
// https://www.linkedin.com/company/devtestco
$companyId = '2414183';

$share = $client->post(
                'ugcPosts',
                [
                    'author' => 'urn:li:organization:' . $companyId,
                    'lifecycleState' => 'PUBLISHED',
                    'specificContent' => [
                        'com.linkedin.ugc.ShareContent' => [
                            'shareCommentary' => [
                                'text' => 'Checkout this amazing PHP SDK for LinkedIn!'
                            ],
                            'shareMediaCategory' => 'ARTICLE',
                            'media' => [
                                [
                                    'status' => 'READY',
                                    'description' => [
                                        'text' => 'OAuth 2 flow, composer Package.'
                                    ],
                                    'originalUrl' => 'https://github.com/zoonman/linkedin-api-php-client',
                                    'title' => [
                                        'text' => 'PHP Client for LinkedIn API'
                                    ]
                                ]
                            ]
                        ]
                    ],
                    'visibility' => [
                        'com.linkedin.ugc.MemberNetworkVisibility' => 'PUBLIC'
                    ]
                ]
            );
print_r($share);
```

##### Setup custom API request headers

[](#setup-custom-api-request-headers)

Change different headers sent to LinkedIn API.

```
$client->setApiHeaders([
  'Content-Type' => 'application/json',
  'x-li-format' => 'json',
  'X-Restli-Protocol-Version' => '2.0.0', // use protocol v2
  'x-li-src' => 'msdk' // set a src header to "msdk" to mimic a mobile SDK
]);
```

##### Change default API root

[](#change-default-api-root)

Some private API access there.

```
$client->setApiRoot('https://api.linkedin.com/v2/');
```

##### Image Upload

[](#image-upload)

I assume you have to be LinkedIn partner or something like that.

Try to upload image to LinkedIn. See [Rich Media Shares](https://docs.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/rich-media-shares)(returns "Not enough permissions to access media resource" for me).

```
$filename = '/path/to/image.jpg';
$client->setApiRoot('https://api.linkedin.com/');
$mp = $client->upload($filename);
```

Contributing
------------

[](#contributing)

Please, open PR with your changes linked to an GitHub issue. You code must follow [PSR](http://www.php-fig.org/psr/) standards and have PHPUnit tests.

License
-------

[](#license)

[MIT](LICENSE.md)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 75.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~99 days

Recently: every ~17 days

Total

19

Last Release

1391d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d4d66c3eac929e6b2c86ff9dc13f7fb05c431d956db07fbe58014f6daf8f55fc?d=identicon)[nhanchaukp](/maintainers/nhanchaukp)

---

Top Contributors

[![zoonman](https://avatars.githubusercontent.com/u/576297?v=4)](https://github.com/zoonman "zoonman (71 commits)")[![nhanchaukp](https://avatars.githubusercontent.com/u/16833818?v=4)](https://github.com/nhanchaukp "nhanchaukp (9 commits)")[![sarhugo](https://avatars.githubusercontent.com/u/974762?v=4)](https://github.com/sarhugo "sarhugo (6 commits)")[![iamsalnikov](https://avatars.githubusercontent.com/u/3082586?v=4)](https://github.com/iamsalnikov "iamsalnikov (5 commits)")[![MattBred](https://avatars.githubusercontent.com/u/17261474?v=4)](https://github.com/MattBred "MattBred (1 commits)")[![danieljpost](https://avatars.githubusercontent.com/u/464951?v=4)](https://github.com/danieljpost "danieljpost (1 commits)")[![saulmoralespa](https://avatars.githubusercontent.com/u/19959663?v=4)](https://github.com/saulmoralespa "saulmoralespa (1 commits)")

---

Tags

apiclientrestauthAuthenticationwrapperoauthoauth2authorizationplatformsocialoauth2-clientintegrationsocial networklinkedinLinkedIn Loginlinked inlinkedin-apiphp-linkedinlinkedin-clientlinkedin-signinlinkedin-sdklinkedin.comoauth2-authentication

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/nhanchaukp-linkedin-api-php-client/health.svg)

```
[![Health](https://phpackages.com/badges/nhanchaukp-linkedin-api-php-client/health.svg)](https://phpackages.com/packages/nhanchaukp-linkedin-api-php-client)
```

###  Alternatives

[zoonman/linkedin-api-php-client

LinkedIn API PHP SDK with OAuth 2.0 &amp; CSRF support. Can be used for social sign in or sharing on LinkedIn. Examples. Documentation.

127704.0k](/packages/zoonman-linkedin-api-php-client)[ezralazuardy/heimdall

Painless OAuth 2.0 Server for CodeIgniter 4

454.2k](/packages/ezralazuardy-heimdall)[artesaos/laravel-linkedin

Linkedin API integration for Laravel and Lumen 5

5666.5k](/packages/artesaos-laravel-linkedin)[chillerlan/php-oauth

A fully transparent, framework agnostic PSR-18 OAuth client.

4210.4k2](/packages/chillerlan-php-oauth)[chervand/yii2-oauth2-server

OAuth 2.0 server for Yii 2.0 with MAC tokens support.

1524.2k1](/packages/chervand-yii2-oauth2-server)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
