{"id":15481626,"url":"https://github.com/zoonman/linkedin-api-php-client","last_synced_at":"2025-04-12T17:42:01.440Z","repository":{"id":24250011,"uuid":"101018021","full_name":"zoonman/linkedin-api-php-client","owner":"zoonman","description":"LinkedIn API PHP SDK with OAuth 2 support. Can be used for social sign in or sharing on LinkedIn. Has a good usage examples","archived":false,"fork":false,"pushed_at":"2024-03-12T12:27:46.000Z","size":198,"stargazers_count":126,"open_issues_count":21,"forks_count":116,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-10T07:04:50.371Z","etag":null,"topics":["composer","linkedin","linkedin-api","linkedin-client","linkedin-login","linkedin-sdk","linkedin-signin","oauth2","oauth2-authentication","oauth2-client","php","sdk"],"latest_commit_sha":null,"homepage":"https://www.zoonman.com/projects/linkedin-client/demo/","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zoonman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-22T03:38:51.000Z","updated_at":"2024-09-07T00:27:11.000Z","dependencies_parsed_at":"2024-06-18T12:37:13.825Z","dependency_job_id":"b8d8e604-a419-42d8-b807-ec3280a62c24","html_url":"https://github.com/zoonman/linkedin-api-php-client","commit_stats":{"total_commits":75,"total_committers":6,"mean_commits":12.5,"dds":"0.17333333333333334","last_synced_commit":"d06531c48d5efc8aaf7dc074a5320f5ba3f906c9"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoonman%2Flinkedin-api-php-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoonman%2Flinkedin-api-php-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoonman%2Flinkedin-api-php-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoonman%2Flinkedin-api-php-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zoonman","download_url":"https://codeload.github.com/zoonman/linkedin-api-php-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248608152,"owners_count":21132669,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["composer","linkedin","linkedin-api","linkedin-client","linkedin-login","linkedin-sdk","linkedin-signin","oauth2","oauth2-authentication","oauth2-client","php","sdk"],"created_at":"2024-10-02T05:05:16.672Z","updated_at":"2025-04-12T17:42:01.406Z","avatar_url":"https://github.com/zoonman.png","language":"PHP","readme":"LinkedIn API Client with OAuth 2 authorization written on PHP\n============================================================\n[![Build Status](https://travis-ci.org/zoonman/linkedin-api-php-client.svg?branch=master)](https://travis-ci.org/zoonman/linkedin-api-php-client) [![Code Climate](https://codeclimate.com/github/zoonman/linkedin-api-php-client/badges/gpa.svg)](https://codeclimate.com/github/zoonman/linkedin-api-php-client) [![Packagist](https://img.shields.io/packagist/dt/zoonman/linkedin-api-php-client.svg)](https://packagist.org/packages/zoonman/linkedin-api-php-client) [![GitHub license](https://img.shields.io/github/license/zoonman/linkedin-api-php-client.svg)](https://github.com/zoonman/linkedin-api-php-client/blob/master/LICENSE.md)\n\n\n\nSee [complete example](examples/) inside [index.php](examples/index.php) to get started.\n\n\n## Installation\n\nYou will need at least PHP 7.3. We match [officially supported](https://www.php.net/supported-versions.php) versions of PHP.\n\nUse [composer](https://getcomposer.org/) package manager to install the lastest version of the package:\n\n```bash\ncomposer require zoonman/linkedin-api-php-client\n```\n\nOr add this package as dependency to `composer.json`.\n\nIf you have never used Composer, you should start [here](http://www.phptherightway.com/#composer_and_packagist)\nand install composer.\n\n\n## Get Started\n\nBefore you will get started, play visit to [LinkedIn API Documentation](https://docs.microsoft.com/en-us/linkedin/).\nThis will save you a lot of time and prevent some silly questions.\n\nTo start working with LinkedIn API, you will need to \nget application client id and secret. \n\nGo to [LinkedIn Developers portal](https://developer.linkedin.com/) \nand create new application in section My Apps. \nSave ClientId and ClientSecret, you will use them later.\n\n\n#### Bootstrapping autoloader and instantiating a client\n\n\n```php\n// ... please, add composer autoloader first\ninclude_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';\n\n// import client class\nuse LinkedIn\\Client;\n\n// instantiate the Linkedin client\n$client = new Client(\n    'YOUR_LINKEDIN_APP_CLIENT_ID',\n    'YOUR_LINKEDIN_APP_CLIENT_SECRET'\n);\n```\n\n#### Getting local redirect URL\n\nTo start linking process you have to setup redirect url. \nYou can set your own or use current one.\nSDK provides you a `getRedirectUrl()` helper for your convenience:\n\n```php\n$redirectUrl = $client-\u003egetRedirectUrl();\n```\n\nWe recommend you to have it stored during the linking session \nbecause you will need to use it when you will be getting access token.\n\n#### Setting local redirect URL \n\nSet a custom redirect url use:\n\n```php\n$client-\u003esetRedirectUrl('http://your.domain.tld/path/to/script/');\n```\n\n#### Getting LinkedIn redirect URL \n\nIn order of performing OAUTH 2.0 flow, you should get LinkedIn login URL.\nDuring this procedure you have to define scope of requested permissions.\nUse `Scope` enum class to get scope names.\nTo get redirect url to LinkedIn, use the following approach:\n\n```php\nuse LinkedIn\\Scope;\n\n// define scope\n$scopes = [\n  Scope::READ_LITE_PROFILE, \n  Scope::READ_EMAIL_ADDRESS,\n  Scope::SHARE_AS_USER,\n  Scope::SHARE_AS_ORGANIZATION,\n];\n$loginUrl = $client-\u003egetLoginUrl($scopes); // get url on LinkedIn to start linking\n```\n\nNow you can take user to LinkedIn. You can use link or rely on Location HTTP header.\n\n#### Getting Access Token \n\nTo get access token use (don't forget to set redirect url)\n\n```php\n$accessToken = $client-\u003egetAccessToken($_GET['code']);\n```\nThis method returns object of `LinkedIn\\AccessToken` class. \nYou can store this token in the file like this:\n```php\nfile_put_contents('token.json', json_encode($accessToken));\n```\nThis way of storing tokens is not recommended due to security concerns and used for demonstration purpose. \nPlease, ensure that tokens are stored securely. \n\n#### Setting Access Token\n\nYou can use method `setAccessToken()` for the `LinkedIn\\Client` class to set token stored as string. You have to pass\ninstance of `LinkedIn\\AccessToken` to this method.\n\n```php\nuse LinkedIn\\AccessToken;\nuse LinkedIn\\Client;\n\n// instantiate the Linkedin client\n$client = new Client(\n    'LINKEDIN_APP_CLIENT_ID',  \n    'LINKEDIN_APP_CLIENT_SECRET'\n);\n\n// load token from the file\n$tokenString = file_get_contents('token.json');\n$tokenData = json_decode($tokenString, true);\n// instantiate access token object from stored data\n$accessToken = new AccessToken($tokenData['token'], $tokenData['expiresAt']);\n\n// set token for client\n$client-\u003esetAccessToken($accessToken);\n```\n\n#### Performing API calls \n\nAll API calls can be called through simple method:\n\n```php\n$profile = $client-\u003eapi(\n    'ENDPOINT',\n    ['parameter name' =\u003e 'its value here'],\n    'HTTP method like GET for example'\n);\n```\n\nThere are 3 helper methods:\n\n```php\n// get method\n$client-\u003eget('ENDPOINT', ['param' =\u003e 'value']);\n\n//post\n$client-\u003epost('ENDPOINT', ['param' =\u003e 'value']);\n\n// delete\n$client-\u003edelete('ENDPOINT');\n```\n\n#### Examples\n\n##### Perform api call to get profile information\n\n```php\n$profile = $client-\u003eget(\n    'me',\n    ['fields' =\u003e 'id,firstName,lastName']\n);\nprint_r($profile);\n```\n\n##### List companies where you are an admin\n\n```php\n$profile = $client-\u003eget(\n    'organizations',\n    ['is-company-admin' =\u003e true]\n);\nprint_r($profile);\n```\n\n##### Share content on a personal profile\n\nMake sure that image URL is available from the Internet (don't use localhost in the image url).\n\n```php\n$share = $client-\u003epost(                 \n                'ugcPosts',                         \n                [                                   \n                    'author' =\u003e 'urn:li:person:' . $profile['id'],\n                    'lifecycleState' =\u003e 'PUBLISHED',\n                    'specificContent' =\u003e [          \n                        'com.linkedin.ugc.ShareContent' =\u003e [\n                            'shareCommentary' =\u003e [\n                                'text' =\u003e 'Checkout this amazing PHP SDK for LinkedIn!'\n                            ],\n                            'shareMediaCategory' =\u003e 'ARTICLE',\n                            'media' =\u003e [\n                                [\n                                    'status' =\u003e 'READY',\n                                    'description' =\u003e [\n                                        'text' =\u003e 'OAuth 2 flow, composer Package.'\n                                    ],\n                                    'originalUrl' =\u003e 'https://github.com/zoonman/linkedin-api-php-client',\n                                    'title' =\u003e [\n                                        'text' =\u003e 'PHP Client for LinkedIn API'\n                                    ]\n                                ]\n                            ]\n                        ]\n                    ],\n                    'visibility' =\u003e [\n                        'com.linkedin.ugc.MemberNetworkVisibility' =\u003e 'CONNECTIONS'\n                    ]\n                ]\n            );\nprint_r($share);\n```\n\n##### Get Company page profile\n\n```php\n$companyId = '123'; // use id of the company where you are an admin\n$companyInfo = $client-\u003eget('organizations/' . $companyId);\nprint_r($companyInfo);\n```\n\n##### Share content on a LinkedIn business page\n\n```php\n// set sandboxed company page to work with\n// you can check updates at\n// https://www.linkedin.com/company/devtestco\n$companyId = '2414183';\n\n$share = $client-\u003epost(                 \n                'ugcPosts',                         \n                [                                   \n                    'author' =\u003e 'urn:li:organization:' . $companyId,\n                    'lifecycleState' =\u003e 'PUBLISHED',\n                    'specificContent' =\u003e [          \n                        'com.linkedin.ugc.ShareContent' =\u003e [\n                            'shareCommentary' =\u003e [\n                                'text' =\u003e 'Checkout this amazing PHP SDK for LinkedIn!'\n                            ],\n                            'shareMediaCategory' =\u003e 'ARTICLE',\n                            'media' =\u003e [\n                                [\n                                    'status' =\u003e 'READY',\n                                    'description' =\u003e [\n                                        'text' =\u003e 'OAuth 2 flow, composer Package.'\n                                    ],\n                                    'originalUrl' =\u003e 'https://github.com/zoonman/linkedin-api-php-client',\n                                    'title' =\u003e [\n                                        'text' =\u003e 'PHP Client for LinkedIn API'\n                                    ]\n                                ]\n                            ]\n                        ]\n                    ],\n                    'visibility' =\u003e [\n                        'com.linkedin.ugc.MemberNetworkVisibility' =\u003e 'PUBLIC'\n                    ]\n                ]\n            );\nprint_r($share);\n```\n\n##### Setup custom API request headers\n\nChange different headers sent to LinkedIn API.\n\n```php\n$client-\u003esetApiHeaders([\n  'Content-Type' =\u003e 'application/json',\n  'x-li-format' =\u003e 'json',\n  'X-Restli-Protocol-Version' =\u003e '2.0.0', // use protocol v2\n  'x-li-src' =\u003e 'msdk' // set a src header to \"msdk\" to mimic a mobile SDK\n]);\n```\n\n##### Change default API root\n\nSome private API access there.\n\n```php\n$client-\u003esetApiRoot('https://api.linkedin.com/v2/');\n```\n\n##### ~Image Upload~ \n\nI assume you have to be LinkedIn partner or something like that.\n\nTry to upload image to LinkedIn. See [Rich Media Shares](https://docs.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/rich-media-shares)\n(returns \"Not enough permissions to access media resource\" for me). \n\n```php\n$filename = '/path/to/image.jpg';\n$client-\u003esetApiRoot('https://api.linkedin.com/');\n$mp = $client-\u003eupload($filename);\n```\n\n## Contributing\n\nPlease, open PR with your changes linked to an GitHub issue.\nYou code must follow [PSR](http://www.php-fig.org/psr/) standards and have PHPUnit tests. \n\n## License\n\n[MIT](LICENSE.md)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoonman%2Flinkedin-api-php-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzoonman%2Flinkedin-api-php-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoonman%2Flinkedin-api-php-client/lists"}