我正在使用
LinkedIn REST API将更新发布到用户时间线.
几天后,我收到来自LinkedIn的内部服务器错误响应,但代码之前有效.
几天后,我收到来自LinkedIn的内部服务器错误响应,但代码之前有效.
PHP:
$postTitle = "hello"; $postDesc = "world "; $submitted-url = "http://example.com"; $submitted-image-url = "http://images.example.com/img/hello.jpg"; $comment = "foobar"; $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);
您的代码是无效的PHP(可能是因为您在发布之前进行了一些编辑?);将其修改为:
原文链接:https://www.f2er.com/php/240126.html$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,'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_POSTFIELDS => json_encode($postData) )); $response = curl_exec($ch);
仅当$oauthToken设置为有效令牌时才有效.假设您的真实代码是正确的,剩下的唯一可能性是您的OAuth令牌已过期,您需要先获取新的令牌.通过添加CURLOPT_VERBOSE =>对于cURL选项,您可以找到有关LinkedIn返回的错误的更多信息.