php – LinkedIn REST API – 内部服务器错误
发布时间:2020-05-25 09:27:10 所属栏目:PHP 来源:互联网
导读:我正在使用 LinkedIn REST API将更新发布到用户时间线. 几天后,我收到来自LinkedIn的内部服务器错误响应,但代码之前有效. PHP: $postTitle = hello;$postDesc = world ;$submitted-url = http://example.com;$submitted-image-url = http://images.e
|
我正在使用
LinkedIn REST API将更新发布到用户时间线.
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返回的错误的更多信息. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
