我在 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/