php – LinkedIn REST API – 内部服务器错误

前端之家收集整理的这篇文章主要介绍了php – LinkedIn REST API – 内部服务器错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用 LinkedIn REST API将更新发布到用户时间线.
几天后,我收到来自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(可能是因为您在发布之前进行了一些编辑?);将其修改为:
$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返回的错误的更多信息.

原文链接:https://www.f2er.com/php/240126.html

猜你在找的PHP相关文章