【问题标题】:Accessing YouTube account for stats from Google Cloud via API通过 API 从 Google Cloud 访问 YouTube 帐户以获取统计信息
【发布时间】:2021-02-18 04:15:55
【问题描述】:

我有一个以 mymanager@gmail.com 为经理的 YouTube 频道。 我已经为我的域 ssss.org 设置了一个 Google Cloud 帐户(免费试用)。 我编写了 OAuth 代码来访问 YT API 并激活了 YT API。 我运行代码并以 me@ssss.org 身份进行身份验证。 我打电话:

$youtube = new Google_Service_YouTube($client);
try {
  $channel = $youtube->channels->listChannels('snippet', ['mine' => TRUE]);...

并收到异常消息:"Unauthorized", "errors": [ { "message": "Unauthorized", "domain": "youtube.header", "reason": "youtubeSignupRequired", "location": "Authorization", "locationType": "header" }

我将 me@ssss.org 添加为 YT 帐户的经理,并点击了“访问 xxx 的邀请”电子邮件中的链接。 这没问题,但随后在提到关于 G Suite 试用的 https://support.google.com/a/answer/9000768 时出现错误。

将 GC 与我的 YT 帐户关联的最佳方法是什么?

【问题讨论】:

    标签: php google-cloud-platform google-api google-oauth google-api-php-client


    【解决方案1】:

    Google Cloud 和 YouTube 真的没有任何关系。我不确定你想用它做什么。

    未经授权的错误

    听起来您没有正确设置授权。它应该弹出并请求用户的授权。您需要使用有权访问您希望查看的数据的用户登录您的代码。

    在这种情况下,如果您想查看 mymanager@gmail.com 拥有的频道,那么您应该以 mymanager@gmail.com 的身份登录。

    此示例检索授权用户的 YouTube 频道的频道数据。它使用 mine 请求参数来指示 API 应该只返回授权请求的用户拥有的频道。

    我的仅适用于您登录的用户所拥有的频道。

    // Load the Google API PHP Client Library.
    require_once __DIR__ . '/vendor/autoload.php';
    
    session_start();
    
    $client = new Google_Client();
    $client->setAuthConfig(__DIR__ . '/client_secrets.json');
    $client->addScope(Google_Service_YouTube::YOUTUBE_READONLY);
    
    
    // If the user has already authorized this app then get an access token
    // else redirect to ask the user to authorize access to Google Analytics.
    if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
      // Set the access token on the client.
      $client->setAccessToken($_SESSION['access_token']);
    
      // Create an authorized analytics service object.
      $service = new Google_Service_YouTube($client);
    
    }
    

    谷歌工作区

    Access to YouTube during your Google Workspace trial

    您的 Google Workspace 帐户的费用至少为 30 美元(或等值的货币)。此金额不包括购买域名的费用。

    如果您的帐户已使用 30 天,并且您直接从 Google 注册了 Google Workspace:您可以提前付款或为更多用户帐户付费以访问所有 YouTube 功能。付款后,最长可能需要 48 小时才能使用功能。

    【讨论】:

    • 嗨@DalmTo - 根据文档,我必须使用 OAuth 才能获得所需的 YT 统计信息。我已经按照您的建议进行了身份验证,即获取弹出窗口等。如果我在以 mymanager@ 身份登录时尝试打开 YT 工作室,我会收到消息说我无法访问并引用 support.google.com/a/answer/9000768 - 我认为这是真正的问题。但是我需要在免费试用期间解决这个问题,以证明一切正常。我该怎么做?
    • @Jons SO 不是 Google 支持,您不会在这里得到 Google 的回复。
    • @DalmTo 你是“谷歌分析和身份平台的谷歌开发专家”,感谢您的回复 - 我如何获得支持,因为这是谷歌云告诉我们要去的领域跨度>
    • 您发布的页面提到要等待三十天才能使用此功能。我建议你等三十天。
    • @DalmTo - 是的,但该页面还显示:“为什么访问受限?为了保持我们的系统健康,我们对 Google Workspace 帐户上传视频、添加 cmets、创建频道和其他需要登录帐户的操作。”这似乎没有意义,因为它与等待 30 天无关(这本身似乎是一个奇怪的随机限制)。所有这些东西都在我的频道上 - 我想做的就是访问它!
    【解决方案2】:

    我确实使用 OAuth 实现了这个功能,并且由于免费试用时间已用完,我升级到了最接近的付费级别。做对是很棘手的——尤其是当它不清楚什么是“对”时。请参阅Need details of credentials setup for Analytics and Reporting API 了解更多信息。

    【讨论】:

      猜你喜欢
      • 2015-07-12
      • 1970-01-01
      • 2015-06-26
      • 2020-02-04
      • 2011-10-31
      • 2018-03-30
      • 1970-01-01
      • 2021-07-20
      • 2015-10-03
      相关资源
      最近更新 更多