Jump to content

linkedin share company post


vaskovasilev

Recommended Posts

hello,

i am trying to find working example for posting to a company page in Linkedin.

i found some articles on stackoverflow .. but nothing:

 

https://stackoverflow.com/questions/21788482/linkedin-company-share-api?rq=1

 

after authenticating, nothing is happening.

 

i asked Linkedin also, but they didnt hepled me.

can you please help me..

function posttopage($method, $resource, $body = '')  {
  //$params = array('visbility' => array('code' => 'anyone'),'comment' => "php test post",'content' => array('submitted-url' => 'webcv', 'title' => 'Test Share with Content' , 'description' => 'content description' , 'submitted-image­url' => 'http://domain/logo.png'),'oauth2_access_token' => $_SESSION['access_token'],'format' => 'json');
  //$params = array('visibility' => array('code' => 'anyone'),'comment' => "php test post", 'share-target-reach' => array('share-targets' => array('share-target' => array('code' => 'geos' , 'tvalues' => array('tvalue'=> 'test body for posting')))));
  //print_r($params);
  //echo "<br><br>".json_encode($params);
  
  $strShare = <<<XML
  <share>
  <visibility>
    <code>anyone</code>
  </visibility>
  <comment>comment share!</comment>
  <content>
    <submitted-­url>http://www.domain</submitted-­url>
    <title>test share from php</title>
    <description>description</description>
    <submitted‐image-­url>http://www.domain/logo.png</submitted-­image-­url>
  </content>
  <share-target-reach>
    <share-targets>
      <share-target>
        <code>geos</code>
        <tvalues>
          <tvalue>IT</tvalue>
        </tvalues>
      </share-target>
    </share-targets>
  </share-target-reach>
</share>
XML;
    
    
  //$params = http_build_query($params);
  //$data_len = strlen ($params);
  //$url = 'https://api.linkedin.com' . $resource .'?'. $params  ;
  $url = 'https://api.linkedin.com' . $resource  ;
  //$context = stream_context_create(
  //array('http' =>
  //array('method' => $method,
//)
//)
//);
  
  
  //$response = file_get_contents($url, false, $context,$data_len);
  //return json_decode($response);
  //echo $url;
$objCurl = curl_init();
curl_setopt($objCurl, CURLOPT_URL, "https://api.linkedin.com/v1/companies/id/shares?format=xml");
curl_setopt($objCurl, CURLOPT_HEADER, 1);
  //curl_setopt($objCurl, CURLOPT_POST, 1);
curl_setopt($objCurl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($objCurl, CURLOPT_POSTFIELDS, $strShare);
  //curl_setopt($objCurl, CURLOPT_HTTPHEADER, array(
  //'Content-Type: application/json',
  //'Connection: Keep-Alive'
  //));
curl_setopt($objCurl, CURLOPT_HTTPHEADER, array(
                                        'Content-Type: application/xml',
                                        'Connection: Keep-Alive'
                                        ));
curl_setopt($objCurl, CURLOPT_RETURNTRANSFER, true);


$response = curl_exec($objCurl);
curl_close($objCurl);
echo $response;
  
  
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.