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);
$profile = $client->api(
'ENDPOINT',
['parameter name' => 'its value here'],
'HTTP method like GET for example'
);
$companyId = '123'; // use id of the company where you are an admin
$companyInfo = $client->get('companies/' . $companyId . ':(id,name,num-followers,description)');
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(
'companies/' . $companyId . '/shares',
[
'comment' => 'Checkout this amazing PHP SDK for LinkedIn!',
'content' => [
'title' => 'PHP Client for LinkedIn API',
'description' => 'OAuth 2 flow, composer Package',
'submitted-url' => 'https://github.com/zoonman/linkedin-api-php-client',
'submitted-image-url' => 'https://github.com/fluidicon.png',
],
'visibility' => [
'code' => 'anyone'
]
]
);
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
]);