Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Youtube API download captions (using PHP example)

Tags:

php

youtube

I'm working from Youtube Data API - Captions: download, Using the PHP example
I can get the list of transcripts successfully,
but cannot download the transcript.
After entering caption track ID and hitting GO, it breaks the page.

If I try a track ID from a video without CC contributions allowed, I get the correct error of:

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.

I've tried excluding the second optional parameter on $youtube->captions->download, with no luck.

It breaks when it tries to print $captionResource (I'm new to debugging 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>';
}
like image 747
Erik Tetland Avatar asked Nov 29 '17 04:11

Erik Tetland


1 Answers

Instead of $captionResource try $captionResource->getBody()->getContents().

like image 108
Joe GI Avatar answered Sep 24 '22 16:09

Joe GI