PHP   发布时间:2022-04-09  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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返回的错误的更多信息.

大佬总结

以上是大佬教程为你收集整理的php – LinkedIn REST API – 内部服务器错误全部内容,希望文章能够帮你解决php – LinkedIn REST API – 内部服务器错误所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。