问题
I have few private videos on my YouTube channel and i want to put them on my website. Basically i don't want my website users to watch them directly on my YouTube channel. Furthermore i don't want to show consent screen to the users either. I browsed and found this example at stackoverflow in which DalmTo is suggesting someone to use Google Service Account to achieve this. My code works fine with publicly available videos but it does not show the private videos whenever i search the video with it's ID.
Here's my code:
<?php
session_start();
require_once('vendor/autoload.php');
$client = new Google_Client();
$client->setApplicationName("YouTube-Example");
$client->setScopes('https://www.googleapis.com/auth/youtube');
putenv("GOOGLE_APPLICATION_CREDENTIALS=service_account.json");
$client->useApplicationDefaultCredentials();
$youtube = new Google_Service_YouTube($client);
try{
$response = $youtube->videos->listVideos(
'snippet',
array(
'id' => 'pW0og1OZurE' //private video unable to display
));
echo "<pre>";
print_r($response);
} catch (Google_Service_Exception $e) {
$htmlBody .= sprintf('<p>A service error occurred: <code>%s</code></p>',
htmlspecialchars($e->getMessage()));
} catch (Google_Exception $e) {
$htmlBody .= sprintf('<p>An client error occurred: <code>%s</code></p>',
htmlspecialchars($e->getMessage()));
}
?>
I followed the documentation but i can't figure out why it's not working. Please help me out.
Thanks in advance.
回答1:
Displaying of private videos is not allowed in Youtube API as stated in the help guide.
Private videos can only be seen by people who have been invited to view the video.
Here are some possible reasons why you or somebody you’ve shared the video with aren’t able to see a private video:
-Viewers need to have a YouTube account and be signed into it when trying to view the video.
-If the viewer has multiple YouTube accounts, they must be signed into the account which the video has been shared with.
-Since private videos don’t appear on a Channel page, the person will need to use the specific link to the private video. YouTube will send them an email with the link once you’ve invited them, but you can also send it yourself.
来源:https://stackoverflow.com/questions/39801170/youtube-data-api-v3-unable-to-display-private-videos-of-my-youtube-channel-on