我尝试使用php和api版本3将视频上传到youtube。
一切都正确完成但我收到以下错误:
致命错误:未捕获的异常' Google_Service_Exception'同 消息'调用POST时出错 https://www.googleapis.com/youtube/v3/videos?part=status%2Csnippet: (403)禁止'在C:\ xampp \ htdocs \ youtube \ Google \ Http \ REST.php:79 堆栈跟踪:#0 C:\ xampp \ htdocs \ youtube \ Google \ Http \ REST.php(44): Google_Http_REST :: decodeHttpResponse(对象(Google_Http_Request))#1 C:\ XAMPP \ htdocs中\的YouTube \谷歌\ Client.php(499): Google_Http_REST ::执行(对象(Google_Client) 对象(Google_Http_Request))#2 C:\ XAMPP \ htdocs中\的YouTube \谷歌\服务\ Resource.php(195): Google_Client->执行(对象(Google_Http_Request))#3 C:\ XAMPP \ htdocs中\的YouTube \谷歌\服务\ YouTube.php(3116): Google_Service_Resource->电话('插入',数组,' Google_Service _...') C:\ xampp \ htdocs \ youtube \ upload.php(60):Google_Service_YouTube_Videos_Resource-> insert(' status,snippet', Object(Google_Service_YouTube_Video),Array)#5 {main}引入 第79行的C:\ xampp \ htdocs \ youtube \ Google \ Http \ REST.php
这是我上传视频的地方
if($client->getAccessToken()) {
$snippet = new Google_Service_YouTube_VideoSnippet();
$snippet->setTitle("Test title2");
$snippet->setDescription("Test descrition");
$snippet->setTags(array("tag1", "tag2"));
$snippet->setCategoryId("22");
$status = new Google_Service_YouTube_VideoStatus();
$status->privacyStatus = "private";
$video = new Google_Service_YouTube_Video();
$video->setSnippet($snippet);
$video->setStatus($status);
$videoData = file_get_contents("out.mp4");
$youtube->videos->insert("status,snippet", $video, array("data" => $videoData, "mimeType" => "out.mp4"));
}