Youtube API 下载字幕(使用 PHP 示例)

Eri*_*and 6 php youtube

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

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

发生服务错误:与请求关联的权限不足以下载字幕轨道。请求可能没有得到正确授权,或者视频订单可能没有为此字幕启用第三方贡献。

我试过在 $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>';
}
Run Code Online (Sandbox Code Playgroud)

小智 1

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