本文介绍了使用LinkedIn V2 API上传视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用LinkedIn API V2上传视频,但无法将视频成功发布到我的LinkedIn个人帐户.请帮忙.

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.

从LinkedIn API返回以下响应:

Returning Below Response from LinkedIn API:

$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);

我需要成功将视频帖子上传到LinkedIn帐户,但我也无法从LinkedIn文档中了解这一点.我已经尝试了很多,但没有成功.请成功通过V2上传视频的人,然后请帮助.

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.

推荐答案

linkedin还没有发布视频上传.您可以使用文章EP("shareMediaCategory":文章")将视频发送到linkedin

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

这篇关于使用LinkedIn V2 API上传视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 04:07