Your code is invalid PHP (perhaps due to some changes that you made before publishing?); changing it to:
$postTitle = "hello"; $postDesc = "world "; $postURL = "http://example.com"; $postImage = "http://images.example.com/img/hello.jpg"; $postComment = "foobar"; $oauthToken = "<token>"; $postData = array( 'visibility' => array('code' => 'connections-only'), 'content' => array( 'title' => $postTitle, 'description' => $postDesc, 'submitted-url' => $postURL, 'submitted-image-url' => $postImage ), 'comment' => $postComment ); $ch = curl_init('https://api.linkedin.com/v1/people/~/shares?oauth2_access_token='.$oauthToken.'&format=json'); curl_setopt_array($ch, array( CURLOPT_POST => TRUE, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_HTTPHEADER => array('x-li-format: json', "Content-Type: application/json"), CURLOPT_POSTFIELDS => json_encode($postData) )); $response = curl_exec($ch);
works if only $oauthToken set to a valid token. Assuming your real code is correct, the only possible possibility is that your OAuth token has expired and you need to get a new one first. By adding CURLOPT_VERBOSE => TRUE to the cURL parameters, you will learn more about the error that LinkedIn returns.
source share