3

I am trying to upload a video using LinkedIn API V2 but I am unable to post successfully video to my LinkedIn Individual Account. Please help.

Returning Below Response from LinkedIn API:

SignatureDoesNotMatch The request signature we calculated does not match the signature you provided. Check your key and signing method.

$person_id=LINKEDIN_ACCOUNT_ID;
$access_token= LINKEDIN_ACCESS_TOKEN;

$share_text='Video Upload and Share Text';
$author = "urn:li:person:".$person_id;

$r_url='https://api.linkedin.com/v2/assets?action=registerUpload';

$r_params = array(
    'registerUploadRequest'=>array(
        'recipes'=>array('urn:li:digitalmediaRecipe:feedshare-video'),                  
        'owner' => $author,
    )
);

$handle = curl_init();
curl_setopt($handle, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($handle, CURLOPT_URL, $r_url);
curl_setopt($handle, CURLOPT_VERBOSE, FALSE);
$header = array();
$header[] ='Authorization : Bearer '.$access_token;
$header[] = 'Content-Type: application/json; charset=UTF-8';

curl_setopt($handle, CURLOPT_HTTPHEADER, $header);
curl_setopt($handle, CURLOPT_POSTFIELDS, json_encode($r_params));
$json1 = curl_exec($handle);
$json1=json_decode($json1,true);

if($json1['value']['uploadMechanism']['com.linkedin.digitalmedia.uploading.MediaUploadHttpRequest']['uploadUrl']){
    $target_url=$json1['value']['uploadMechanism']['com.linkedin.digitalmedia.uploading.MediaUploadHttpRequest']['uploadUrl'];

    $return_header=$json1['value']['uploadMechanism']['com.linkedin.digitalmedia.uploading.MediaUploadHttpRequest']['headers'];
    $parts = parse_url($target_url);
    parse_str($parts['query'], $query);

    $amz_signature=$query['X-Amz-Signature'];

    $target_header=array();

    $target_header[]='Host: video-uploads-prod.s3-accelerate.amazonaws.com';
    $target_header[]="Content-Type:".trim($return_header['Content-Type']);

    $target_header[]="x-amz-server-side-encryption:".trim($return_header['x-amz-server-side-encryption']);
    $target_header[]='x-amz-server-side-encryption-aws-kms-key-id:'.trim($return_header['x-amz-server-side-encryption-aws-kms-key-id']);


    $video_path = DIR_PATH_TO_VIDEO_FILE.'example_video.mp4';

    $post_data=array('file'=>$video_path);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_URL,$target_url);
    curl_setopt($ch, CURLOPT_VERBOSE, FALSE);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $target_header);

    curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents($video_path));

    $json2=curl_exec ($ch);
    curl_close ($ch);

    $json2=json_decode($json2,true);

    $media_id=str_replace('urn:li:digitalmediaAsset:','', $json1['value']['asset']);

    $return_data=array();
    $check_url = 'https://api.linkedin.com/v2/assets/'.$media_id;

    $handle = curl_init();
    curl_setopt($handle, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($handle, CURLOPT_HEADER, FALSE);
    curl_setopt($handle, CURLOPT_URL, $check_url);
    $header = array();
    $header[] ='Authorization : Bearer '.$access_token;
    $header[] = 'Content-Type: application/json; charset=UTF-8';
    curl_setopt($handle, CURLOPT_HTTPHEADER,$header);
    $return_data= curl_exec($handle);
    $return_data= json_decode($return_data,true);


    $author = "urn:li:person:".$person_id;

    $post_url = 'https://api.linkedin.com/v2/ugcPosts';
    $media_data=array();
    $media_data[0]=array(
            'status'=>'READY',
            'description'=>array('text'=>'Official LinkedIn Blog'),
            'media'=>$media_id,
            'title'=>array('text'=>"Official LinkedIn Blog"),
        );

    $params = array(
        'author' => $author,
        'lifecycleState' => 'PUBLISHED',
        'specificContent' => array(
            'com.linkedin.ugc.ShareContent' => array(
                'shareCommentary' => array(
                    'text' => "Video media set in post",
                ),
                'shareMediaCategory' => 'VIDEO',
                'media'=>$media_data,
                'originalUrl'=>'https://www.google.com'
            )
        ),
        'visibility' => array(
            'com.linkedin.ugc.MemberNetworkVisibility' => 'PUBLIC'
        )
    );


    $handle = curl_init();
    curl_setopt($handle, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($handle, CURLOPT_URL, $post_url);
    curl_setopt($handle, CURLOPT_VERBOSE, FALSE);
    curl_setopt($handle, CURLOPT_POSTFIELDS, json_encode($params));
    $header = array();
    $header[] ='Authorization : Bearer '.$access_token;
    $header[] = 'Content-Type: application/json; charset=UTF-8';
    $header[] = 'X-Restli-Protocol-Version:2.0.0';
    curl_setopt($handle, CURLOPT_HTTPHEADER, $header);
    $json3 = curl_exec($handle);
    $json3=json_decode($json3);

I need to upload video post to LinkedIn Account successfully but I am unable to understand that from LinkedIn documentation too. I have tried so much but not succeed. Please someone who has successfully uploaded a video with V2 then please help.

Repute
  • 31
  • 1
  • 4

2 Answers2

1

Hi linkedin not released video uploads yet.You can use the article EP( "shareMediaCategory": "ARTICLE") to send videos to linkedin

augustine jenin
  • 424
  • 4
  • 10
  • Hi Augustine. Why does LinkedIn have the documentation for it, but it is not supported yet? Do you know for sure that video upload is not supported yet? How do you know it? – Alain Vanderbroeck May 02 '19 at 12:19
  • I read it somewhere but i don't remember the link.I was also searching for video upload.Now i use the article posting.So i will generate a dynamic page of video.So it will make preview of video. We should generate an image of corresponding video. you can check buffer also to check this. – augustine jenin May 02 '19 at 12:37
  • Oke, thank you for your answer. I believe you of course, because my POC does not work. LinkedIn refers to Stack overflow for API support. But no one call tell me for sure that it is not working, and obviously no one can tell when it is going to work. I think that is not the way it should be. I am frustrated about this. – Alain Vanderbroeck May 03 '19 at 09:30
  • The solution you mention does work of course. It is a good alternative. – Alain Vanderbroeck May 03 '19 at 09:31
  • @Alain good to hear.Reffre this url to generate dynamic page of video https://video.buffer.com/v/5ccc172be34b015c107cf2e7. Did you get the permission for manage company page posting? – augustine jenin May 03 '19 at 10:27
  • Yes, we have got all the permissions. thank you for your answer and reference! – Alain Vanderbroeck May 07 '19 at 12:14
  • how long it takes to get approved from linkedin? – augustine jenin May 07 '19 at 12:24
  • It took exactly a month to get our API access approved via the LinkedIn's Marketing Developer Program. – Alain Vanderbroeck May 08 '19 at 14:04
  • @augustinejenin Could you post a sample request of the relevant article share? Did you use the ugcPost endpoint? Or the v2/share endpoint? Do you upload the video to LinkedIn or include a url of the video in the media array of the article share? More clarification on this regard would be really nice, considering how detailed the documentation is, and how royally it fails even with provisioned app credentials... (video multipart uploads) – EffectiX May 20 '19 at 19:45
  • is there any update in this? In the documentation there is a notification that video posts are restircted to certain developers. https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/ugc-post-api – Alain Vanderbroeck Nov 01 '19 at 11:27
  • When i read the oktober update mail, they will discontinue the RIchMedia API on January 2020. Can we conclude that video UGC Posts will work by then? – Alain Vanderbroeck Nov 01 '19 at 11:28
1

I make use of the LinkedIn API from Zoonman to do the client post request, but this is out of the scope of the question.

Because i could not get the php curl functions to work properly, i am using the command line interface to do the request, and it works! See my code below.

BUT. even tough the upload works. When i do a request to get the status of the upload, it is still "WAITING_UPLOAD". So i think @augustine jenin is right, that it is not supported yet. (may 2019)

<?php
// first register upload
$data = [
 "registerUploadRequest" => [
  "recipes" => [
   "urn:li:digitalmediaRecipe:feedshare-video"
  ],
  "owner" => "urn:li:organization:" . $liPageId,
  "serviceRelationships"=> [
   [
    "relationshipType"=> "OWNER",
    "identifier" => "urn:li:userGeneratedContent"
   ]
  ]
 ]
];
    
$register = $client->post('assets?action=registerUpload', $data);

// get upload url and header
$uploadUrl = $register["value"]["uploadMechanism"]["com.linkedin.digitalmedia.uploading.MediaUploadHttpRequest"]["uploadUrl"];
$headers = $register["value"]["uploadMechanism"]["com.linkedin.digitalmedia.uploading.MediaUploadHttpRequest"]["headers"];
    
$curlHeaders = "";
foreach($headers as $htype => $header) {
 $curlHeaders .= ' -H "' . $htype . ':' . $header . '"';
}

// go upload the image to the url
$filePath = "/path/to/your/file";

$command = '/usr/bin/curl -v';
$command .= $curlHeaders;
$command .= ' --upload-file \'' . $filePath . '\' \'' . $uploadUrl . '\'';

// try it yourself by running this on the command line
//echo $command;

shell_exec($command);

?>
Alain Vanderbroeck
  • 325
  • 1
  • 2
  • 10