我正在设置根据用户要发布的内容发布到LinkedIn的功能。这些选项当前仅是文本或带有链接的文本。仅发布文本是没有问题的,但是当我尝试添加链接时,我收到来自LinkedIn的不清楚的错误。
我用来将请求传递给cURL的代码是:
$Header[] = 'Content-Type: application/json';
$Header[] = 'x-li-format: json';
$Header[] = 'X-Restli-Protocol-Version: 2.0.0';
$Header[] = 'Authorization: Bearer <ACCESS TOKEN>';
$Header[] = 'Content-Length: ' . strlen(json_encode($FieldsArray));
$Curl = curl_init('https://api.linkedin.com/v2/ugcPosts');
curl_setopt($Curl, CURLOPT_POST, true);
curl_setopt($Curl, CURLOPT_HTTPHEADER, $Header);
curl_setopt($Curl, CURLOPT_POSTFIELDS, json_encode($FieldsArray));
curl_setopt($Curl, CURLOPT_RETURNTRANSFER, true);
$Response = curl_exec($Curl);
curl_close($Curl);
$ FieldsArray是以下数组。
array(4) {
["specificContent"]=>
array(1) {
["com.linkedin.ugc.ShareContent"]=>
array(3) {
["media"]=>
array(2) {
["status"]=>
string(5) "READY"
["originalUrl"]=>
string(24) "<URL>"
}
["shareCommentary"]=>
array(1) {
["text"]=>
string(4) "test"
}
["shareMediaCategory"]=>
string(7) "ARTICLE"
}
}
["author"]=>
string(28) "urn:li:organization:<ORGANIZATION ID>"
["lifecycleState"]=>
string(9) "PUBLISHED"
["visibility"]=>
array(1) {
["com.linkedin.ugc.MemberNetworkVisibility"]=>
string(11) "PUBLIC"
}
}
使用没有URL和shareMediaCategory的类似数组:无返回以下内容:
object(stdClass)#15 (1) { ["id"]=> string(32) "urn:li:share:<SHARE ID>" }
我希望上面的数组有类似的东西,但是响应是:
Unknown dereferenced type ARRAY for DataMap's schema { "type" : "array", "items" : { "type" : "record", "name" : "ShareMedia", "namespace" : "com.linkedin.ugc", "doc" : "Media that has been shared.", "fields" : [ { "name" : "title", "type" : { "type" : "record", "name" : "AttributedText", "namespace" : "com.linkedin.common", "doc" : "A text with attributes within it", "fields" : [...
任何帮助将不胜感激。
谢谢。
答案 0 :(得分:1)
由于JSON请求对象中的媒体格式错误,我收到此错误。但是,我相信您的情况是您错误地指定了媒体资产。请参阅以下API文档,以上传图像并获取用于发布的digitalMediaAsset ID:https://docs.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/share-on-linkedin#create-an-image-share
在对请求进行json_encoding之前的PHP中,以下格式对我有用。
$postStatus['specificContent']['com.linkedin.ugc.ShareContent']['shareMediaCategory'] = 'IMAGE';
$postStatus['specificContent']['com.linkedin.ugc.ShareContent']['media'][] = $media;
其中 $ media 本身是一个数组:
Array
(
[status] => READY
[media] => urn:li:digitalmediaAsset:abc123
)
注意:在您提出请求之前,数字媒体资产可能未完全上传。您可以使用Assets API来检查图像的状态:https://docs.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/vector-asset-api