为什么我上传照片到LinkedIn API时会出现客户端错误?
我正在使用LinkedIn v2 api进行图像共享。有三个步骤,根据为什么我上传照片到LinkedIn API时会出现客户端错误?,linkedin,linkedin-api,php-curl,Linkedin,Linkedin Api,Php Curl,我正在使用LinkedIn v2 api进行图像共享。有三个步骤,根据 注册要上载的图像 将您的图像上载到LinkedIn 创建图像共享 在完成步骤2之后,我用/v2/assets/{assetid}检查上传的状态,并得到一个“CLIENT_ERROR”。我不知道这意味着什么,也没有在LinkedIn文档或在线上找到太多关于它的信息。它可能与按照LinkedIn的要求上传一个二进制图像文件有关,但据我所知,我正在上传一个 编辑:下面是我用来上传图片的php curl。$uploadUrl是从映像
> GET /v2/assets/{redacted} HTTP/1.1
User-Agent: curl/7.35.0
Host: api.linkedin.com
Accept: */*
Authorization: Bearer {redacted}
< HTTP/1.1 200 OK
< X-LI-ResponseOrigin: RGW
< Content-Type: application/json
< X-RestLi-Protocol-Version: 1.0.0
< Content-Length: 319
< Date: Wed, 20 Mar 2019 14:09:18 GMT
< X-Li-Fabric: prod-ltx1
< Connection: keep-alive
< X-Li-Pop: prod-edc2-nkernB
< X-LI-Proto: http/1.1
< X-LI-UUID: {redacted}
< Set-Cookie: {redacted}
< X-LI-Route-Key: {redacted}
更新:使用命令行curl上传图像时效果良好:
curl -i --upload-file {file} --header "Authorization: Bearer {auth}" {url}
更新:解决方案:
使用file_get_contents:curl_setopt($ch,CURLOPT_POSTFIELDS,file_get_contents({图像路径));**
这个:curl\u setopt($ch,CURLOPT\u POSTFIELDS,file\u get\u contents({图像路径));
$ch = curl_init($uploadUrl);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch,CURLOPT_USERAGENT,'curl/7.35.0');
$authorizationHeader = trim("Authorization: Bearer $accessToken");
curl_setopt($ch, CURLOPT_HTTPHEADER, array($authorizationHeader,"Content-Type: {$mimeType}","X-Restli-Protocol-Version: 2.0.0"));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents({path-to-your-image));
$response = curl_exec($ch);
将头添加到代码中,作为
内容类型:应用程序/octet流授权:承载${access\u token}
“X-Restli-Protocol-Version”:“2.0.0”
“内容类型”:“图像/jpg”
body只是图像文件内容或BLOB
方法:POST或PUT…我猜其中一个对某些人有效,第二个对其他人有效你是如何上传你的图像的?你从/assets API收到了什么HTTP响应和头文件?更新:当我使用命令行curl上传图像时效果很好:(curl-i--upload file{file}--header“Authorization:Bearer{auth}{url}”对我来说,上传文件时,通过提供正确的内容类型
标题,已修复了客户端错误
状态。这似乎无法修复OP的问题,但可能会帮助其他人!
curl -i --upload-file {file} --header "Authorization: Bearer {auth}" {url}
$ch = curl_init($uploadUrl);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch,CURLOPT_USERAGENT,'curl/7.35.0');
$authorizationHeader = trim("Authorization: Bearer $accessToken");
curl_setopt($ch, CURLOPT_HTTPHEADER, array($authorizationHeader,"Content-Type: {$mimeType}","X-Restli-Protocol-Version: 2.0.0"));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents({path-to-your-image));
$response = curl_exec($ch);
$ch = curl_init($uploadUrl);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch,CURLOPT_USERAGENT,'curl/7.35.0');
$authorizationHeader = trim("Authorization: Bearer $accessToken");
curl_setopt($ch, CURLOPT_HTTPHEADER, array($authorizationHeader,"Content-Type: {$mimeType}","X-Restli-Protocol-Version: 2.0.0"));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents({path-to-your-image));
$response = curl_exec($ch);