php - Google API的php客户端库-YouTube分块上传错误

标签 php youtube youtube-api google-api-php-client

我正在使用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/

相关文章:

youtube - YouTube 数据 API v3 的 `.../auth/youtube.download` 范围是什么?

PhPmyadmin SQL 查询插入元键和值(如果存在另一个值)

youtube - 如何告诉youtube我的网站是嵌入式视频的流量来源

Youtube 分析 API 403 错误

java - 带有谷歌身份验证的 CircularRedirectException

python - discord py音乐机器人停止播放

javascript - 使用 YouTube API 通过电子邮件或用户名获取用户 YouTube 播放列表

php - 如何覆盖/添加到 Laravel 中的密码代理?

php - 本地主机子文件夹 PHP

php - Laravel Collection Get 方法未按预期工作