Search the Community
Showing results for tags 'linkedin'.
-
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; }
-
Hello, I am very new to php, I have some ability with vba but of no help with this project. I am trying to help a small nonprofit with a Linkedin project. I found this code here it does a part of what I need, it collects the authentication token from the first user that gives permission to do so. The problem is it only collects the first user authentication token and I need it to collect all users authentication tokens. Thanks for any help <?php /** * This is just for illustrative purposes. Ideally should be a user object and based on a real database */ class TokenDB { static $file = 'token.storage'; public static function getToken(){ return @file_get_contents(TokenDB::$file); } public static function setToken($t){ file_put_contents(TokenDB::$file,$t); } public static function resetToken(){ file_put_contents(TokenDB::$file,''); } } include '../simplelinkedin.class.php'; //Set up the API $ln = new SimpleLinkedIn('xxxx', 'yyyy'); //Set the current consumer token as the one stored in our DB. $ln->setTokenData(TokenDB::getToken()); if($ln->authorize()){ try { //Do some OAuth requests... $user = $ln->fetch('GET', '/v1/people/~:(firstName,lastName)'); print "Hello $user->firstName $user->lastName."; //Update stored token. $tokenData = $ln->getTokenData(); TokenDB::setToken($tokenData['access_token']); } catch(SimpleLinkedInException $e){ //If token was expired or invalid, we reset and reauthorize. if($e->getLastResponse()->status == 401){ //reset the stored token, so we can go through the authorization process //again at page refresh TokenDB::resetToken(); //Reauthorize.. $ln->authorize(); exit; } else throw $e; } } ?>