【问题标题】:Unable to post a comment in Linkedin via api in PHP无法通过 PHP 中的 api 在 Linkedin 中发表评论
【发布时间】:2023-01-11 19:06:11
【问题描述】:

我在 PHP 中工作,并尝试在 linkedin 中使用 php 中的 API 发表评论,但出现以下错误

{"message":"java.util.concurrent.ExecutionException: com.linkedin.restli.server.RestLiServiceException [HTTP Status:400]: com.linkedin.restli.client.RestLiResponseException: Response status 400, serviceErrorMessage: Comments are not supported for threadUrn: urn:li:ugcPostUrn","status":400}

这是我当前的代码

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.linkedin.com/rest/socialActions/ugcPostUrn/comments');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n   \"actor\":\"urn:li:person:uegvbUDWQm\",\n   \"object\":\"urn:li:activity:6509167547709943808\",\n   \"message\":{\n      \"text\":\"commentV2 with image entity\"\n   },\n   \"content\":[\n      {\n         \"entity\":{\n            \"digitalmediaAsset\":\"urn:li:digitalmediaAsset:C552CAQGu16obsGZENQ\"\n         },\n         \"type\":\"IMAGE\"\n      }\n   ]\n}");

$headers = array();
$headers[] = 'Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$headers[] = 'Linkedin-Version: 202208';
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
print_R($result);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);

【问题讨论】:

    标签: php api


    【解决方案1】:

    在我看来,您使用了错误的端点。请尝试:

    https://api.linkedin.com/v2/socialActions/{target}/comments

    您可以在 LinkedIn 应用程序上查看可用端点列表: List of endpoints

    我使用了这些端点并且工作正常。

    【讨论】:

    • 我如何使用这些端点,请告诉我我的代码有什么问题?你能在我的代码中解释或编辑吗,这样我就可以在我这边检查和实施
    • 什么应该替换为“目标”?
    猜你喜欢
    • 1970-01-01
    • 2011-11-09
    • 2013-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-08
    • 1970-01-01
    • 2015-09-20
    相关资源
    最近更新 更多