我会上传使用与PHP卷曲的Youtube API V3的视频,如下所述:https://developers.google.com/youtube/v3/docs/videos/insert在Youtube上传的视频使用curl和API V3
我有这个功能
function uploadVideo($file, $title, $description, $tags, $categoryId, $privacy)
{
$token = getToken(); // Tested function to retrieve the correct AuthToken
$video->snippet['title'] = $title;
$video->snippet['description'] = $description;
$video->snippet['categoryId'] = $categoryId;
$video->snippet['tags'] = $tags; // array
$video->snippet['privacyStatus'] = $privacy;
$res = json_encode($video);
$parms = array(
'part' => 'snippet',
'file' => '@'.$_SERVER['DOCUMENT_ROOT'].'/complete/path/to/'.$file
'video' => $res
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.googleapis.com/upload/youtube/v3/videos');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parms);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$token['access_token']));
$return = json_decode(curl_exec($ch));
curl_close($ch);
return $return;
}
但退货
stdClass Object
(
[error] => stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[domain] => global
[reason] => badContent
[message] => Unsupported content with type: application/octet-stream
)
)
[code] => 400
[message] => Unsupported content with type: application/octet-stream
)
)
该文件是MP4。
任何人都可以帮忙吗?
谢谢!我试图让东西更轻,但我会尝试谷歌官方库 – genna
在Google_YoutubeService.php中我找不到调用我需要的插入方法的函数。所有方法都列出(频道,播放列表,视频..) 我必须等待较新版本的图书馆? – genna
由于缺少我需要的方法,我决定使用Zend_Gdata_YouTube和API的第二个版本 – genna