1
votes

I have a YouTube channel with [email protected] as the manager. I have set up a Google Cloud account for my domain ssss.org (Free trial). I have written OAuth code to access the YT API and activated YT APIs. I run the code and authenticate as [email protected]. I called:

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

and got the exception message: "Unauthorized", "errors": [ { "message": "Unauthorized", "domain": "youtube.header", "reason": "youtubeSignupRequired", "location": "Authorization", "locationType": "header" }

I added [email protected] as a manager on the YT account and clicked the link in the ‘Invitation to access xxx’ email. This was ok but then gave error referring to https://support.google.com/a/answer/9000768 which is about G Suite trials.

What is best way to link GC with my YT account?

2

2 Answers

0
votes

Google cloud and YouTube really have nothing to do with each other. Im not really sure what you are trying to do with it.

Unauthorized error

Sounds like you haven't set up the authorization properly. It should popup and request authorization of the user. You need to login to your code with the user that has access to the data you wish to see.

In this case if you want to see the channels owned by [email protected] then you would login as [email protected].

This example retrieves the channel data for the authorized user's YouTube channel. It uses the mine request parameter to indicate that the API should only return channels owned by the user authorizing the request.

mine only works with channels that are owned by the user you are logging in as.

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

}

Google workspace

Access to YouTube during your Google Workspace trial

Your Google Workspace account has been billed for at least USD $30 (or equivalent in your currency). This amount doesn’t include the cost to purchase your domain.

If you’ve had your account for 30 days and you signed up for Google Workspace directly from Google: You can make an early payment or pay for more users accounts to access all YouTube features. After you make the payment, it might take up to 48 hours before features are available.

0
votes

I did get this to work using OAuth, and as I'd run out of free trial time I upgraded to the nearest paid level. It's tricky to get right - especially when its not clear what 'right' is. See Need details of credentials setup for Analytics and Reporting API for more info.