php - Youtube API 下载字幕(以PHP为例)

标签 php youtube

我在 Youtube Data API - Captions: download 工作, 使用 PHP 示例
我可以成功获取成绩单列表,
无法下载成绩单
输入字幕轨道 ID 并点击 GO 后,它会中断页面​​。

如果我在不允许 CC 贡献的情况下尝试从视频中获取轨道 ID,我会得到以下正确错误:

A service error occurred: The permissions associated with the request are not sufficient to download the caption track. The request might not be properly authorized, or the video order might not have enabled third-party contributions for this caption.

我尝试在 $youtube->captions->download 上排除第二个可选参数,但没有成功。

它在尝试打印 $captionResource 时中断(我是调试 PHP 的新手)

//(original from Youtube API examples)  
function downloadCaption(Google_Service_YouTube $youtube, $captionId, &$htmlBody) {
    // Call the YouTube Data API's captions.download method to download an existing caption.
    $captionResouce = $youtube->captions->download($captionId, array(
        'tfmt' => "srt",
        'alt' => "media"
    ));

    $htmlBody .= "<h2>Downloaded caption track</h2><ul>";
    $htmlBody .= sprintf('<li>%s</li>',
      $captionResouce);
    $htmlBody .= '</ul>';
}

最佳答案

尝试使用 $captionResource->getBody()->getContents() 而不是 $captionResource

关于php - Youtube API 下载字幕(以PHP为例),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47545109/

相关文章:

ruby - Ruby 的最佳 YouTube gem?

php - Mysql查询以确定给定的日期时间是否包含在日期时间间隔中

php - 保护可从 Android 访问的 REST API

html - 通过 PHP/AJAX 发送 html 代码时,它会转义双引号

jquery - 如何在 jQuery 中延迟加载非图像内容?

javascript - 如何使用chrome扩展名控制youtube视频?

php - SQL 字符串正确但 fetchAll 为空

php - Laravel Dingo API 和 Middleware\\VerifyCsrfToken.php 问题

ios - 如何使用 Expo 播放 Youtube 视频

c# - YouTube API v3 检查视频处理状态