1

This call is referenced in step 2 of the docs here

I am following the docs to create an image and text share in LinkedIn through the version 2 API. Following the steps in the docs, I completed each step with a successful response. However, my post does not exist in LinkedIn, and cannot be viewed by direct link based on the ID returned by the API request

In debuging I made a get request to https://api.linkedin.com/v2/assets/C5622AQFbyxMfU2b9zg. This is to retrieve the media asset (docs here) created in the first step. It returned the following json with the 'CLIENT_ERROR' status. If you look at the docs though, this status is not one of those listed for the field

{
    "serviceRelationships": [
        {
            "identifier": "urn:li:userGeneratedContent",
            "relationshipType": "OWNER"
        }
    ],
    "recipes": [
        {
            "recipe": "urn:li:digitalmediaRecipe:feedshare-image",
            "status": "CLIENT_ERROR"
        }
    ],
    "mediaTypeFamily": "STILLIMAGE",
    "created": 1550875198973,
    "lastModified": 1550875199857,
    "id": "C5622AQFbyxMfU2b9zg",
    "status": "ALLOWED"
}

I was able to successfully upload the file using the command line curl. It seems the issue is with my PHP implementation. Specifically the upload of the binary file is not working right. Here is a simplified representation of my php code.

    $ch = curl_init();

    $headers = [
        'Authorization: Bearer ' . $this->accessToken->access_token,
        'Cache-Control: no-cache',
        'X-RestLi-Protocol-Version: 2.0.0',
        'x-li-format: json',
        'Content-Type: ' . $this->mimetype
    ];

    $data = [
        'file' => curl_file_create($filename, $this->mimetype);
    ];

    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_URL, 'https://api.linkedin.com/mediaUpload/C5622AQHSLBWkZeg-gQ/feedshare-uploadedImage/0?ca=vector_feedshare&cn=uploads&m=AQJIFvVUxXl7yAAAAWkwjT0kEPKHY5BnAgXETcVQ3AbsxmvaGl6hnuECwA&app=22961836&sync=0&v=beta&ut=2RaKRdHD_OwUE1');
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    $result = curl_exec($ch);
    print_r($result);
  • Please submit a ticket to linkedin.zendesk.com including all of this information, as well as the response headers received with each of your requests. – Christopher Ou Feb 27 '19 at 00:36
  • @ChristopherOu Already done. Thank you though. – Jonathan Reissmueller Feb 27 '19 at 16:43
  • This is possibly a duplicate of [this question](https://stackoverflow.com/questions/54538939/how-to-convert-curl-call-with-i-upload-file-into-java-unirest-or-any-other), but it is php specific so I think it is distinct – Jonathan Reissmueller Feb 27 '19 at 21:13
  • @JonathanReissmueller , I have the same problem exactly like you but in java, Did you find a solution? – Ahmed E. Eldeeb Mar 31 '19 at 15:03
  • Sadly no. I contacted developer support and they essentially said "Implementing it in your language is your problem." Since the issue is converting it into your chosen language though I don't think that a solution I find will be useful to you. – Jonathan Reissmueller Apr 01 '19 at 15:38

1 Answers1

1

I ran into this same issue recently and linkedin's documents were not very helpful. Create an Image Share.

The first thing to understand is that "curl --upload-file" uses a PUT request method. Here is what I used using dummy data.

$file = "/storage/media/testimg.jpg";
$uploadurl = "https://api.linkedin.com/mediaUpload/C5622AQHSLBWkZeg-gQ/feedshare-uploadedImage/0?ca=vector_feedshare&cn=uploads&m=AQJIFvVUxXl7yAAAAWkwjT0kEPKHY5BnAgXETcVQ3AbsxmvaGl6hnuECwA&app=22961836&sync=0&v=beta&ut=2RaKRdHD_OwUE1";
$accesstoken = "acacdsv13rv31bv13b1cf13cf13rv13rv13vr13tb5dxvghn";
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $uploadurl);
curl_setopt($curl_handle, CURLOPT_PUT, 1);
curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, "PUT");
$fh_res = fopen($file, 'r');
curl_setopt($curl_handle, CURLOPT_INFILE, $fh_res);
curl_setopt($curl_handle, CURLOPT_INFILESIZE, filesize($file));
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
$headers[] = "Authorization: Bearer $accesstoken"; //linkedin says to add 'redacted' instead of access token (that's bullshit)
$headers[] = 'Connection: Keep-Alive';
$headers[] = "X-RestLi-Protocol-Version:2.0.0";
curl_setopt($curl_handle,CURLOPT_HTTPHEADER,$headers);
$rcurl = curl_exec($curl_handle);
curl_close($curl_handle);

If you dump the response $rcurl you only get an empty string. So the next step is to check the status of the upload, something they completely forgot to mention as part of the image share documentation but can be found here Check Status of Uphold

Using the asset variable from the initial image register call, you check the upload's status until the status check returns AVAILABLE.

$asset = "urn:li:digitalmediaAsset:C4asdfvqqrv3";
$a = explode("digitalmediaAsset:", $asset);            
$statuscheck =  make a GET curl call to the url: "/assets/" . $a[1]         
$uploadstat = $statuscheck['recipes'][0]['status'];
do{
    $statuscheck =  make a GET curl call to the url: "/assets/" . $a[1];
    $uploadstat = $statuscheck['recipes'][0]['status'];
}while($uploadstat != 'AVAILABLE');

Once AVAILABLE is returned, you can now proceed to the next step of creating the image share. Hope this helps.

AbdelAziz AbdelLatef
  • 3,650
  • 6
  • 24
  • 52
iMilan
  • 11
  • 1