I'm now working with Linkedin V2 integration with my application. I'm facing an issue while trying to upload image to Linkedin.
I have tried CURL request from my terminal(I'm using Ubuntu OS) & getting response as below:
Terminal command (Working & file uploaded):
curl -i --upload-file /Users/peter/Desktop/superneatimage.png --header "Authorization: Bearer redacted" 'https://api.linkedin.com/mediaUpload/C5522AQGTYER3k3ByHQ/feedshare-uploadedImage/0?ca=vector_feedshare&cn=uploads&m=AQJbrN86Zm265gAAAWemyz2pxPSgONtBiZdchrgG872QltnfYjnMdb2j3A&app=1953784&sync=0&v=beta&ut=2H-IhpbfXrRow1'
It's response as below:
HTTP/2 201 date: Wed Apr 10 09:14:44 UTC 2019 server: Play set-cookie: lang=v=2&lang=en-us; Path=/; Domain=api.linkedin.com x-ambry-creation-time: Wed Apr 10 09:14:44 UTC 2019 access-control-allow-origin: https://www.linkedin.com content-length: 0
I'm facing issue when I integrate the CURL request in my application. My CURL request code from my application is given below.
$headers = array();
$headers[] = 'Authorization: Bearer xxxxx';
$headers[] = 'X-Restli-Protocol-Version: 2.0.0';
$headers[] = 'Content-Type: multipart/form-data';
$ch = curl_init();
$options = array(
CURLOPT_HEADER => true,
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => 'https://api.linkedin.com/mediaUpload/C5522AQGTYER3k3ByHQ/feedshare-uploadedImage/0?ca=vector_feedshare&cn=uploads&m=AQJbrN86Zm265gAAAWemyz2pxPSgONtBiZdchrgG872QltnfYjnMdb2j3A&app=1953784&sync=0&v=beta&ut=2H-IhpbfXrRow1',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => array("upload-file" => '/Users/peter/Desktop/superneatimage.png')
// CURLOPT_POSTFIELDS => array("upload-file" => new CURLFile('/Users/peter/Desktop/superneatimage.png'))
);
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
print_r($response);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
Response as:
HTTP/1.1 400 Bad Request Server: Play Set-Cookie: lang=v=2&lang=en-us; Path=/; Domain=api.linkedin.com Date: Wed, 10 Apr 2019 09:16:25 GMT Content-Length: 0 X-Li-Fabric: prod-lsg1 Connection: keep-alive
Similar question from SO, which do not solved my issue.
@was the way to do file uploads, but that is deprecated since PHP 5.5.0, so what you should be using is php.net/manual/en/class.curlfile.php - 04FS@before image path as you said but it did not helped me. Used PHP 7 - Sinto