LinkedIn使用API重新共享ugcPost

LinkedIn使用API重新共享ugcPost,linkedin,linkedin-api,Linkedin,Linkedin Api,我正在尝试使用V2 API重新共享ugcPost 我已经使用v2/shares完成了这项工作。我收到内部服务器错误 如果有人尝试过这个方法,请告诉我这是否可行?你应该在你的标题中添加X-Restli-Protocol-Version:2.0.0不确定你是否知道这个数字,但我花了一段时间,所以我想把它扔出去,除非其他人遇到这个问题。对我来说,我没有使用responseContext来引用父帖子。这就是我的工作 "author": "urn:li:person:#{uid of user}",

我正在尝试使用V2 API重新共享ugcPost

我已经使用v2/shares完成了这项工作。我收到内部服务器错误


如果有人尝试过这个方法,请告诉我这是否可行?

你应该在你的标题中添加X-Restli-Protocol-Version:2.0.0

不确定你是否知道这个数字,但我花了一段时间,所以我想把它扔出去,除非其他人遇到这个问题。对我来说,我没有使用responseContext来引用父帖子。这就是我的工作

  "author": "urn:li:person:#{uid of user}",
  "lifecycleState": "PUBLISHED",

  #this part here
  "responseContext": {
    "parent": "urn:li:share:6577220936284545024",
    "root": "urn:li:share:6577220936284545024"
   },

   "specificContent": {
     "com.linkedin.ugc.ShareContent": {
       "shareMediaCategory": "NONE",
        "shareCommentary": {
          "text": "Comment here about the reshared post."
        },
        "media": [],
        "shareCategorization": {}
      }
    },
    "visibility": {
      "com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
    }
和标题应该是

    {
      "Authorization" => "Bearer #{token}",
      "Content-Type" => 'application/json',
      "X-Restli-Protocol-Version" => "2.0.0"
    }

ugcPost的重新共享应使用ugcPost文档中模式中的“responseContext”:

以下是重新共享ugcPost的示例调用:

卷曲:

红宝石:

PHP:


你有没有想过?我遇到了同样的问题。我一直有500个错误<代码>“作者”:“urn:li:person:”,“lifecycleState:“PUBLISHED”,“specific content:{“com.linkedin.ugc.ShareContent:{“shareMediaCategory:”urn\u REFERENCE”,“ShareCommentation:{“text:”这是linkedin的再共享“},“media:[{“media:”“urn:li:share:6577220936284545024”,“状态”:“就绪”}],
Reg共享对我来说很好。我实际上使用的是
/ugcPosts
端点。正如我前面提到的,社交帖子和图片的定期共享工作很好。你有这个标题吗?如果有,你介意详细说明你的解决方案吗?
curl --location --request POST 'https://api.linkedin.com/v2/ugcPosts' \
--header 'x-li-format: json' \
--header 'X-Restli-Protocol-Version: 2.0.0' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ACCESS_TOKEN' \
--data-raw '{  "lifecycleState": "PUBLISHED",
  "visibility": {
    "com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
  },
  "specificContent": {
    "com.linkedin.ugc.ShareContent": {
      "shareMediaCategory": "NONE",
      "shareCommentary": {
        "text": ""
      }
    }
  },
  "responseContext": {
    "parent": "urn:li:ugcPost:123",
    "root": "urn:li:ugcPost:123"
  },
  "author": "urn:li:person:123"
}'
require "uri"
require "net/http"

url = URI("https://api.linkedin.com/v2/ugcPosts")

https = Net::HTTP.new(url.host, url.port);
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-li-format"] = "json"
request["X-Restli-Protocol-Version"] = "2.0.0"
request["Content-Type"] = ["application/json", "application/json"]
request["Authorization"] = "Bearer ACCESS_TOKEN"
request.body = payload.to_json

response = https.request(request)
puts response.read_body
<?php
$client = new http\Client;
$request = new http\Client\Request;
$request->setRequestUrl('https://api.linkedin.com/v2/ugcPosts');
$request->setRequestMethod('POST');
$body = new http\Message\Body;
$body->append('{
    "lifecycleState": "PUBLISHED",
    "visibility": {
        "com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
    },
    "specificContent": {
        "com.linkedin.ugc.ShareContent": {
            "shareMediaCategory": "NONE",
            "shareCommentary": {
                "text": ""
            }
        }
    },
    "responseContext": {
        "parent": "urn:li:ugcPost:123",
        "root": "urn:li:ugcPost:123"
    },
    "author": "urn:li:person:123"
}');
$request->setBody($body);
$request->setOptions(array());
$request->setHeaders(array(
  'x-li-format' => 'json',
  'X-Restli-Protocol-Version' => '2.0.0',
  'Authorization' => 'Bearer ACCESS_TOKEN',
  'Content-Type' => 'application/json'
));
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();