vaskovasilev Posted March 6, 2015 Share Posted March 6, 2015 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-imageurl' => '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; } Quote Link to comment https://forums.phpfreaks.com/topic/295150-linkedin-share-company-post/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.