我正在使用LinkedIn v2 api进行图像共享。根据{{3}},该过程分为三个步骤。
我使用php curl超过了前两个,但是我陷在第三个。 步骤3,使用ugcPost完成。
这是我发送给ugc端点的帖子正文:
{
"author": "urn:li:person:{id-redacted}",
"lifecycleState": "PUBLISHED",
"specificContent": {
"com.linkedin.ugc.ShareContent": {
"shareCommentary": {
"text": "hello"
},
"shareMediaCategory": "IMAGE",
"media": {
"stats": "READY",
"description": {
"text": "this is a descriptoin"
},
"media": "urn:li:digitalmediaAsset:{id-redacted}",
"title": {
"text": "this is some title text"
}
}
}
},
"visibility": {
"com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
}
}
这是我用来通过php发送curl post请求的代码:
curl_setopt($ch, CURLOPT_URL, $ugcPostEndpoint);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_STDERR, $out);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json","X-Restli-Protocol-Version: 2.0.0"));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
$response = curl_exec($ch);
$response_status = strval(curl_getinfo($ch, CURLINFO_HTTP_CODE));
从curl返回此值:
Hostname was found in DNS cache
Trying 108.174.10.12...
Connected to api.linkedin.com (108.174.10.12) port 443 (#2)
successfully set certificate verify locations:
CAfile: none
CApath: /etc/ssl/certs
SSL connection using {redacted}
Server certificate:
subject: C=US; ST=California; L=Mountain View; O=LinkedIn Corporation; CN=tablet.linkedin.com
start date: 2018-03-30 00:00:00 GMT
expire date: 2020-04-27 12:00:00 GMT
subjectAltName: api.linkedin.com matched
issuer: C=US; O=DigiCert Inc; CN=DigiCert SHA2 Secure Server CA
SSL certificate verify ok.
POST /v2/ugcPosts?oauth2_access_token={redacted} HTTP/1.1
Host: api.linkedin.com
Accept: */*
Content-Type:application/json
X-Restli-Protocol-Version: 2.0.0
Content-Length: 734
upload completely sent off: 734 out of 734 bytes
< HTTP/1.1 500 Server Error
< X-LI-ResponseOrigin: RGW
< Content-Type: application/json
< X-RestLi-Error-Response: true
< X-Restli-Gateway-Error: false
< X-RestLi-Protocol-Version: 2.0.0
< X-Li-Fabric: prod-ltx1
< Transfer-Encoding: chunked
< Connection: keep-alive
< X-Li-Pop: prod-edc2
< X-LI-Proto: http/1.1
< X-LI-UUID: {redacted}
< Set-Cookie: {redacted}
< X-LI-Route-Key: {redacted}
<
Connection #2 to host api.linkedin.com left intact
为什么会出现此500错误?据我所知,我正在关注所有示例/文档。 (我知道500个错误最终可能是一个问题,但是根据我的经验,在处理API时,500个错误通常意味着curl请求在某种程度上是错误的。
答案 0 :(得分:1)
我弄清楚了我在做错什么,以防其他人遇到类似的问题。
主体的媒体部分必须是这样的数组中的第0个元素:
"media": [
{
"status": "READY",
"description": {
"text": "this is a description"
},
"media": "urn:li:digitalmediaAsset:{id}",
"title": {
"text": "this is some title text"
}
}
]
不是这样的:
"media":
{
"status": "READY",
"description": {
"text": "this is a description"
},
"media": "urn:li:digitalmediaAsset:{id}",
"title": {
"text": "this is some title text"
}
}
LinkedIn文档并没有使其变得如此明显。