【发布时间】:2019-08-06 22:46:27
【问题描述】:
我正在使用 LinkedIn v2 api 制作图像共享。分三步,根据the LinkedIn docs.
- 注册要上传的图片。
- 将您的图片上传到 LinkedIn。
- 创建图像共享。
我使用 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 请求在某种程度上是错误的。
【问题讨论】:
-
您是否将 OAuth 2.0 访问令牌添加到
Authorization标头?
标签: php curl linkedin linkedin-api php-curl