I would like to get the company posts from LinkedIn in PHP. What request should I use to ask for the post?
I try to use PHP library "zoonman/linkedin-api-php-client". I have created LinkedIn application with a verified access to the company. I wrote the code that get LinkenIn access token. I try to use GET 'companies' request but I receive errors 404 or 410.
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// add Composer autoloader
include_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor/autoload.php';
// import client class
use LinkedIn\Client;
use LinkedIn\Scope;
use LinkedIn\AccessToken;
// instantiate the Linkedin client
$client = new Client(
'correct client id',
'correct client secret'
);
$scopes = [
Scope::READ_BASIC_PROFILE
];
$client->setRedirectUrl("correct return address, which is the same as URL of current script");
$loginUrl = $client->getLoginUrl($scopes);
if (isset($_GET) && isset($_GET['code']))
{
$accessToken = $client->getAccessToken($_GET['code']);
$client->setAccessToken($accessToken);
$client->setApiRoot('https://api.linkedin.com/v1/'); //I've tried to use 'https://api.linkedin.com/v2/' too
$client->setApiHeaders([
'Content-Type' => 'application/json',
'x-li-format' => 'json',
'X-Restli-Protocol-Version' => '2.0.0', // use protocol v2
]);
$posts = $client->get('/v1/companies/10239645/updates?format=json');
//I've tried to use '/v2/companies/10239645/updates?format=json'
//and '/companies/10239645/updates?format=json'
var_dump($posts);
die();
}
else
{
header('Location: ' . $loginUrl);
}
I receive client errors ('GuzzleHttp\Exception\ClientException') depending on the address of the request:
- "
GET https://api.linkedin.com/companies/10239645/updates?format=json
resulted in a404 Not Found
response" - "
GET https://api.linkedin.com/v1/companies/10239645/updates?format=json
resulted in a410 Gone
response: { "errorCode": 0, "message": "This resource is no longer available under v1 APIs", "requestId": "CH17ME6WK6", "s (truncated...)"; - "
GET https://api.linkedin.com/v2/companies/10239645/updates?format=json
resulted in a404 Not Found
response: {"serviceErrorCode":0,"message":"Resource companies does not exist","status":404}".
I would like to get the company posts from LinkedIn.
Is the request 'companies' is disabled now? What request (and request address) should I use? How to get the company posts from LinkedIn now? What is wrong in my code? Could you help me?