Linkedin API post to company page

i read a lot of article about how to send share with php into linkedin.

finally i can share things to user profile.

but i need to send share into company page with php.

here is my code:

<?php
require_once("OAuth.php");
session_start();
$data = array(
    'consumer_key' => 'XXXXXXXXXXXX',
    'consumer_secret' => 'XXXXXXXXXXXXX',
    'callback_url' => ''
);

$method = new OAuthSignatureMethod_HMAC_SHA1();
$consumer = new OAuthConsumer($data['consumer_key'], $data['consumer_secret']);

$access_token = unserialize($_SESSION['oauth_access_token']); // as we got from last tutorial <a href="http://www.tricksofit.com/2015/09/get-user-access-token-for-linkedin" target="_blank"><strong>get user Access Token for LinkedIn</strong></a>

$title = "Tests";
$targetUrl = "http://google.com";
$imgUrl = "http://images5.fanpop.com/image/photos/30900000/beautiful-pic-different-beautiful-pictures-30958249-500-375.jpg";
$description= "In this tutorial I will show you how to Auto Post on LinkedIn using linkedIn Access Token and LinkedIn API with OAuth PHP Library.";

$shareUrl = "http://api.linkedin.com/v1/people/~/shares";
$xml = "<share>";
$xml .= "<content>
<title>$title</title>
<description>$description</description>";
if(!empty($targetUrl)){
    $xml .= "<submitted-url>$targetUrl</submitted-url>";
}

if(!empty($imgUrl)){
    $xml .= "<submitted-image-url>$imgUrl</submitted-image-url>";
}
$xml .= "</content>
  <visibility>
    <code>anyone</code>
  </visibility>
</share>";

$request = OAuthRequest::from_consumer_and_token($consumer, $access_token, "POST", $shareUrl);
$request->sign_request($method, $consumer, $access_token);
$auth_header = $request->to_header("https://api.linkedin.com");
$shareUrl = "http://api.linkedin.com/v1/companies/11111111/shares?format=json";
$response = httpRequest($shareUrl, $auth_header, "POST", $xml);
var_dump($response);
function httpRequest($url, $auth_header, $method, $body = NULL) {
    if (!$method) {
        $method = "GET";
    }

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array($auth_header)); // Set the headers.

    if ($body) {
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array($auth_header, "Content-Type: text/xml;charset=utf-8"));
    }

    $data = curl_exec($curl);
    curl_getinfo($curl, CURLINFO_HTTP_CODE);
    curl_close($curl);
    return $data;
}

the docs says use http://api.linkedin.com/v1/companies/11111111/shares?format=json to post share on company page , but still no luck!.

after i run my code i receive below error:

"errorCode": 0,
  "message": "[unauthorized]. OAU:81wc4ut29iy0ie|d8d73ca6-7589-4242-afec-c50c5039bbfe|*01|*01:1495660605:XHOuCrYLxQHaQCaHpY3vU0d023Q4=",
  "requestId": "WGWRLR9ZMT",
  "status": 401,

Note that : this code work like charm (if i comment http://api.linkedin.com/v1/companies/11111111/shares?format=json line) for user profile, but i need it for company page

thanks in advance


Source: stackoverflow-php