【发布时间】:2017-02-09 14:26:15
【问题描述】:
我的 YouTube 频道上的私人视频很少,我想将它们放到我的网站上。基本上我不希望我的网站用户直接在我的 YouTube 频道上观看他们。此外,我也不想向用户显示同意屏幕。我在 stackoverflow 上浏览并找到 this 示例,其中 DalmTo 建议某人使用 Google 服务帐户来实现此目的。我的代码适用于公开视频,但每当我使用其 ID 搜索视频时,它都不会显示私人视频。
这是我的代码:
<?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()));
}
?>
我遵循了文档,但我无法弄清楚它为什么不起作用。请帮帮我。
提前致谢。
【问题讨论】:
标签: youtube youtube-api youtube-data-api