It's been a week and I cannot post to the company page. The below code works but it's sending to my personal profile instead of the company page. Anyone can advise, please?
<?php
require_once '../vendor/autoload.php';
use GuzzleHttp\Client;
$link = 'www.google.com';
$access_token = 'MY_ACCESS_TOKEN';
$linkedin_id = 'EWg7hNHQ9F';
$body = new \stdClass();
$body->content = new \stdClass();
$body->content->contentEntities[0] = new \stdClass();
$body->text = new \stdClass();
$body->content->contentEntities[0]->thumbnails[0] = new \stdClass();
$body->content->contentEntities[0]->entityLocation = $link;
$body->content->contentEntities[0]->thumbnails[0]->resolvedUrl = "https://picsum.photos/200/300";
$body->content->title = 'Testing Only';
$body->owner = 'urn:li:person:'.urlencode($linkedin_id);
$body->text->text = 'Testing summary';
$body_json = json_encode($body, true);
try {
$client = new Client(['base_uri' => 'https://api.linkedin.com']);
$response = $client->request('POST', '/v2/shares', [
// $response = $client->request('POST', '/v2/ugcPosts', [
'headers' => [
'X-Restli-Protocol-Version' => '2.0.0',
"Authorization" => "Bearer " . $access_token,
"Content-Type" => "application/json",
// "x-li-format" => "json"
],
'body' => $body_json,
]);
if ($response->getStatusCode() !== 201) {
echo 'Error: '. $response->getLastBody()->errors[0]->message;
}
echo 'Post is shared on LinkedIn successfully.';
} catch(Exception $e) {
echo $e->getMessage(). ' for link '. $link;
}