访问YouTube帐户,通过API从谷歌云获取统计数据



我有一个YouTube频道mymanager@gmail.com作为经理。我已经为我的域名ssss.org建立了一个谷歌云帐户(免费试用(。我编写了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邀请"电子邮件中的链接。这还可以,但在提到https://support.google.com/a/answer/9000768这是关于G Suite的试用版。

将GC和我的YT帐户联系起来的最佳方式是什么?

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

未经授权的错误

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

在这种情况下,如果您想查看mymanager@gmail.com然后您将以mymanager@gmail.com.

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

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

// 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);
}

谷歌工作区

在谷歌工作区试用期间访问YouTube

您的谷歌工作区账户已被收取至少30美元(或相当于您的货币(的费用。此金额不包括购买您的域名的费用。

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

我确实使用OAuth实现了这一点,由于我的免费试用时间已经用完,我升级到了最接近的付费级别。这很难正确-尤其是当不清楚什么是"正确"时。有关更多信息,请参阅分析和报告API凭据设置的必要详细信息。

最新更新