1

这是我正在使用的功能:

function uploadVideo($file, $title, $description, $tags, $categoryId, $privacy, $tokenacc){
$direccionvideo = $_SERVER['DOCUMENT_ROOT'].'/uploadyt/mp4/'.$file;
$video->snippet['title']         = $title;
$video->snippet['description']   = $description;
$video->snippet['categoryId']   = $categoryId;
$video->snippet['tags']       = array($tags); // array

$video->status['privacyStatus'] = $privacy;

$res = json_encode($video);

$parms = array(
'part'  => 'snippet, status',
    'file'  => '@'.$direccionvideo,
    'body' => $res
);

$cabeceras = array('Authorization: Bearer '.$tokenacc, 'Content-Type: video/mp4');

$ch = curl_init('https://www.googleapis.com/upload/youtube/v3/videos?part=snippet,status&key=AIXXXXXXXXXXXXXXXXX');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parms);
curl_setopt($ch, CURLOPT_HTTPHEADER, $cabeceras);
$return = curl_exec($ch);
curl_close($ch);

return $return;
}

但它返回这个:

{ "kind": "youtube#video", "etag": "\"rFqCJSkEICLP3Hq6a4AADI7kf48/Ppz1_LDXz9KAv4eC-UouSKrhjn4\"", "id": "XXXXXXXXX", "snippet": { "publishedAt": "2013-07-15T03:06:45.000Z", "channelId": "UCWXN1EzwIl2clMliTxxO7ww", **"title": "unknown"**, **"description": ""**, "thumbnails": { "default": { "url": "https://i1.ytimg.com/vi/XXXXXXXX/default.jpg" }, "medium": { "url": "https://i1.ytimg.com/vi/XXXXXXXX/mqdefault.jpg" }, "high": { "url": "https://i1.ytimg.com/vi/XXXXXXXX/hqdefault.jpg" } }, "channelTitle": "ChannelYouTube", "categoryId": "2" }, "status": { "uploadStatus": "uploaded", "privacyStatus": "public", "license": "youtube", "embeddable": true, "publicStatsViewable": true } }

上传标题为“未知”的视频(您无法处理),没有描述、标签和类别。

就好像 API 不使用任何 post 字段一样。

任何人都可以帮忙吗?

4

0 回答 0