我正在使用Google API的PHP客户端库,并且在使用此解决方案时:
https://stackoverflow.com/a/14552052/1181479
和这里一样
https://developers.google.com/youtube/v3/code_samples/php#resumable_uploads
女巫包含以下逻辑:
if ($client->getAccessToken()) {
$videoPath = "path/to/foo.mp4";
$snippet = new Google_VideoSnippet();
$snippet->setTitle("Test title2");
$snippet->setDescription("Test descrition");
$snippet->setTags(array("tag1", "tag2"));
$snippet->setCategoryId("22");
$status = new Google_VideoStatus();
$status->privacyStatus = "private";
$video = new Google_Video();
$video->setSnippet($snippet);
$video->setStatus($status);
$chunkSizeBytes = 1 * 1024 * 1024;
$media = new Google_MediaFileUpload('video/mp4', null, true, $chunkSizeBytes);
$media->setFileSize(filesize($videoPath));
$result = $youtube->videos->insert("status,snippet", $video,
array('mediaUpload' => $media));
$status = false;
$handle = fopen($videoPath, "rb");
while (!$status && !feof($handle)) {
$chunk = fread($handle, $chunkSizeBytes);
$uploadStatus = $media->nextChunk($result, $chunk);
}
fclose($handle);
}
主要问题是此错误:
ErrorException [ Recoverable Error ]: Argument 1 passed to Google_MediaFileUpload::nextChunk() must be an instance of Google_HttpRequest, instance of Google_Video given, called in /opt/code/host/resulinkpro/www/application/classes/Controller/Upload.php on line 132 and defined
这些东西的核心是:
$ media 是Google_Video类
和
$media->nextChunk($result, $chunk);
要求 $ result 为Google_HttpRequest,因此Google文档以及网络上的任何示例根本都无法帮助您完成该任务!你们最后的机会!
谢谢!
最佳答案
这两个示例都是针对PHP客户端0.6.3制作的,我相信您正在1.0版本中尝试过。您可以阅读有关migrating here的信息。
我们希望能尽快发布更新后的示例。
关于php - Google API的php客户端库-YouTube分块上传错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20342251/