PHP code example of lbolanos / linkedin-api-php-client
1. Go to this page and download the library: Download lbolanos/linkedin-api-php-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lbolanos / linkedin-api-php-client example snippets
// ... please, add composer autoloader first
// instantiate the Linkedin client
$client = new Client(
'YOUR_LINKEDIN_APP_CLIENT_ID',
'YOUR_LINKEDIN_APP_CLIENT_SECRET'
);
$companyId = '123'; // use id of the company where you are an admin
$companyInfo = $client->get('organizations/' . $companyId);
print_r($companyInfo);
// 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);
$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
]);