Erik Tetland
Erik Tetland

Reputation: 73

Youtube API download captions (using PHP example)

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>';
}

Upvotes: 6

Views: 2474

Answers (1)

Joe GI
Joe GI

Reputation: 29

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

Upvotes: 1

Related Questions