YouTube - Data API v3 无法使用 Google 服务帐户在我的网站上显示我的 YouTube 频道的私人视频 [英] YouTube - Data API v3 Unable to display private videos of my YouTube channel on my website using Google Service Account

查看:34
本文介绍了YouTube - Data API v3 无法使用 Google 服务帐户在我的网站上显示我的 YouTube 频道的私人视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 YouTube 频道上的私人视频很少,我想将它们放在我的网站上.基本上我不希望我的网站用户直接在我的 YouTube 频道上观看它们.此外,我也不想向用户显示同意屏幕.我浏览并找到了这个 stackoverflow 中的示例,其中 DalmTo 建议某人使用 Google 服务帐户来实现此目的.我的代码适用于公开可用的视频,但每当我使用其 ID 搜索视频时,它都不会显示私人视频.

这是我的代码:

setApplicationName("YouTube-Example");$client->setScopes('https://www.googleapis.com/auth/youtube');putenv("GOOGLE_APPLICATION_CREDENTIALS=service_account.json");$client->useApplicationDefaultCredentials();$youtube = 新 Google_Service_YouTube($client);尝试{$response = $youtube->videos->listVideos('片段',大批('id' =>'pW0og1OZurE'//私人视频无法显示));echo "

";打印_r($响应);} catch (Google_Service_Exception $e) {$htmlBody .= sprintf('<p>发生服务错误:<code>%s</code></p>',htmlspecialchars($e->getMessage()));} catch (Google_Exception $e) {$htmlBody .= sprintf('<p>发生客户端错误:<code>%s</code></p>',htmlspecialchars($e->getMessage()));}?>

我遵循了文档,但我不知道为什么它不起作用.请帮帮我.

提前致谢.

解决方案

在 Youtube API 中不允许将私人视频显示为 在帮助指南中说明.

<块引用>

私人视频只有被邀请的人才能看到观看视频.

以下是您或您分享的某些人的一些可能原因视频无法看到私人视频:

-观看者需要拥有 YouTube 帐户并在尝试观看视频时登录该帐户.

-如果观看者有多个 YouTube 帐户,则他们必须登录共享视频的帐户.

-由于私人视频不会出现在频道页面上,因此此人需要使用指向私人视频的特定链接.YouTube 将发送邀请他们后,向他们发送一封带有链接的电子邮件,但您也可以自己发送.

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.

解决方案

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.

这篇关于YouTube - Data API v3 无法使用 Google 服务帐户在我的网站上显示我的 YouTube 频道的私人视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆