PHPackages                             avansaber/php-linkedin-api - 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. avansaber/php-linkedin-api

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

avansaber/php-linkedin-api
==========================

Modern, fluent, framework-agnostic PHP client for the LinkedIn API (Marketing Developer Platform)

v1.0.0(9mo ago)03MITPHPPHP ^8.1CI failing

Since Aug 8Pushed 8mo agoCompare

[ Source](https://github.com/avansaber/avansaber-php-linkedin-api)[ Packagist](https://packagist.org/packages/avansaber/php-linkedin-api)[ Docs](https://github.com/avansaber/php-linkedin-api)[ RSS](/packages/avansaber-php-linkedin-api/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (6)Versions (3)Used By (0)

avansaber/php-linkedin-api
==========================

[](#avansaberphp-linkedin-api)

Modern, fluent, framework-agnostic PHP client for the LinkedIn API (Marketing Developer Platform).

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

[](#installation)

```
composer require avansaber/php-linkedin-api
```

Requires PHP &gt;= 8.1. This is a library; do not commit composer.lock in apps consuming this library.

Getting Started
---------------

[](#getting-started)

- Create a LinkedIn Developer App and request access to the Marketing Developer Platform if needed.
- Obtain Client ID and Client Secret.
- Configure OAuth Redirect URI.

Authentication (Authorization Code Flow, PKCE optional)
-------------------------------------------------------

[](#authentication-authorization-code-flow-pkce-optional)

```
use Avansaber\LinkedInApi\Auth\Auth;
use Avansaber\LinkedInApi\Auth\Pkce;
use Avansaber\LinkedInApi\Auth\Scope;

$auth = new Auth();
$state = bin2hex(random_bytes(16));
$authUrl = $auth->getAuthUrl(
    clientId: 'your-client-id',
    redirectUri: 'https://your-app/callback',
    scopes: [Scope::R_LITEPROFILE->value, Scope::W_MEMBER_SOCIAL->value],
    pkce: null, // or new Pkce($codeVerifier, $codeChallenge)
    state: $state
);
// Redirect user to $authUrl

// On callback, exchange the code for a token (perform the HTTP request using your HTTP client)
$params = $auth->getAccessToken('client-id', 'client-secret', $_GET['code'], 'https://your-app/callback', null);
// $params['endpoint'] and $params['params'] contain the token endpoint and form params
```

Client Setup
------------

[](#client-setup)

```
use Avansaber\LinkedInApi\Http\ClientConfig;
use Avansaber\LinkedInApi\Http\LinkedInApiClient;
use Nyholm\Psr7\Factory\Psr17Factory;
use Http\Client\Curl\Client as CurlClient; // any PSR-18 client

$psr17 = new Psr17Factory();
$http = new CurlClient();
$config = new ClientConfig(linkedInVersion: '202401');
$client = new LinkedInApiClient($http, $psr17, $psr17, $config, 'ACCESS_TOKEN');
```

Usage Examples
--------------

[](#usage-examples)

### Fetch profile (Me)

[](#fetch-profile-me)

```
use Avansaber\LinkedInApi\Resources\Me;
$me = new Me($client);
$profile = $me->get(); // tries /rest/me then falls back to /v2/me
```

### Fetch organization

[](#fetch-organization)

```
use Avansaber\LinkedInApi\Resources\Organizations;
$orgs = new Organizations($client);
$org = $orgs->get(123456);
```

### Create UGC post

[](#create-ugc-post)

```
use Avansaber\LinkedInApi\Resources\UgcPosts;
use Avansaber\LinkedInApi\Data\Requests\PostCreateRequest;
$ugc = new UgcPosts($client);
$resp = $ugc->create(new PostCreateRequest('urn:li:organization:123', 'Hello World'));
```

### Get post (REST)

[](#get-post-rest)

```
use Avansaber\LinkedInApi\Resources\Posts;
$posts = new Posts($client);
$post = $posts->get('urn:li:ugcPost:abc');
```

### SocialActions (comments/likes)

[](#socialactions-commentslikes)

```
use Avansaber\LinkedInApi\Resources\SocialActions;
$sa = new SocialActions($client);
$comments = $sa->comments('urn:li:ugcPost:abc');
$likes = $sa->likes('urn:li:ugcPost:abc');
```

### Pagination iterator

[](#pagination-iterator)

```
use Avansaber\LinkedInApi\Http\PaginatorIterator;
$iter = PaginatorIterator::iterate(function(int $start, int $count) use ($client) {
    return $client->get('organizations?q=vanityName&vanityName=linkedin&start='.$start.'&count='.$count, [], false);
}, 10);
foreach ($iter as $row) { /* ... */ }
```

### Media uploads (initialize + PUT)

[](#media-uploads-initialize--put)

```
use Avansaber\LinkedInApi\Media\MediaUploadHelper;
$helper = new MediaUploadHelper($client, $psr17);
$init = $helper->initializeImageUpload('urn:li:organization:123');
$uploadUrl = $init['value']['uploadUrl'];
$helper->uploadBinary($uploadUrl, file_get_contents('/path/image.jpg'));
```

Error Handling
--------------

[](#error-handling)

Typed exceptions are thrown on non-2xx responses:

- AuthenticationException (401)
- PermissionException (403)
- NotFoundException (404)
- ValidationException (400)
- RateLimitException (429) with Retry-After
- ServerException (5xx)

The client captures `X-LI-UUID` from responses for troubleshooting.

Scopes &amp; Access
-------------------

[](#scopes--access)

- Member/profile: `r_liteprofile`, `r_emailaddress`, `w_member_social`
- Organization: `r_organization_social`, `w_organization_social`, `rw_organization_admin`
- Marketing/Ads (availability varies): `r_ads`, `rw_ads`, `r_campaigns`, `rw_campaigns`

Many Marketing Developer Platform endpoints require partner/whitelisting.

CI &amp; Quality
----------------

[](#ci--quality)

- PHPUnit test suite with retry/backoff tests
- PHPStan static analysis
- GitHub Actions matrix for PHP 8.1–8.3

Roadmap
-------

[](#roadmap)

- Chunked media upload (videos/documents)
- More resources and request DTOs (campaign creation/update)
- Integration tests examples

Modern LinkedIn API Support (2025 Update)
-----------------------------------------

[](#modern-linkedin-api-support-2025-update)

This package now supports LinkedIn's modern OpenID Connect API while maintaining backward compatibility.

### ✅ Recommended Modern Scopes

[](#-recommended-modern-scopes)

```
use Avansaber\LinkedInApi\Auth\Scope;

// Modern OpenID Connect scopes (recommended)
$scopes = [
    Scope::OPENID->value,    // Use your name and photo
    Scope::PROFILE->value,   // Use your name and photo
    Scope::EMAIL->value,     // Use the primary email address
];

// Or use the helper method
$scopes = Scope::getModernProfileScopes();
```

### 📱 Modern Profile Fetching

[](#-modern-profile-fetching)

```
use Avansaber\LinkedInApi\Resources\Me;

$me = new Me($client);

// Modern approach - uses OpenID Connect userinfo endpoint
$profile = $me->getUserInfo(); // Recommended

// Response format (OpenID Connect standard):
// {
//   "sub": "linkedin-user-id",
//   "name": "John Doe",
//   "given_name": "John",
//   "family_name": "Doe",
//   "email": "john@example.com",
//   "picture": "https://..."
// }
```

### ⚠️ Migration from Legacy API

[](#️-migration-from-legacy-api)

Legacy ScopeModern Equivalent`r_liteprofile``openid` + `profile``r_emailaddress``email`The package automatically handles fallbacks from modern to legacy endpoints for maximum compatibility.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance58

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

283d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5685bdccb475a5abb647fc1daeb97aff5e44ac72e59f8048ff3772ac4c7ae1e0?d=identicon)[mailnike](/maintainers/mailnike)

---

Top Contributors

[![mailnike](https://avatars.githubusercontent.com/u/22786232?v=4)](https://github.com/mailnike "mailnike (6 commits)")

---

Tags

psr-7apirestadspsr-18marketinglinkedin

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[amazon-php/sp-api-sdk

Amazon Selling Partner API - PHP SDK

133374.1k1](/packages/amazon-php-sp-api-sdk)[retailcrm/api-client-php

PHP client for RetailCRM API

68981.8k1](/packages/retailcrm-api-client-php)[wellrested/wellrested

Simple PHP Library for RESTful APIs

4818.7k4](/packages/wellrested-wellrested)[art4/requests-psr18-adapter

Use WordPress/Requests as a PSR-18 HTTP client

153.3k](/packages/art4-requests-psr18-adapter)[chillerlan/php-httpinterface

A PSR-7/17/18 http message/client implementation

1417.1k5](/packages/chillerlan-php-httpinterface)

PHPackages © 2026

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