Google Apps Script offers to interact with the YouTube API by adding the YouTube Data API v3 as an advanced service and then using the YouTube class. This works fine for me when I handle requests like fetching video details. But it doesn't work with updating a video, or getting my own videos - i.e. requests that require OAuth2.
Important: My YouTube channel has a brand account. So when I authenticate the script, I select that account.
Here is a simple example. I create a new script () and execute the function below.
function showMyChannels() {
const channels = YouTube.Channels.list(["snippet"], { mine: true });
console.log(channels)
}
When this function is running for the first time, an OAuth2 authentication flow is triggered in a popup. When I select my personal Google account, it works, and the list of channels is empty. However, when I select my YouTube brand account, it does not work:
- The authentication flow in the popup seems to have finished.
- The script is also visible as a 3rd party on the page , as it should be.
- However, the Google Apps Script console writes:
"Access to your Google account is required to run this project. Please try again and allow access this time." (translated with DeepL, my interface is in German).
How to fix this?
Let me say that I can actually update my videos programmatically within a Node.js application, the googleapis Node.js client and the whole refresh token procedure. (In that setting I also needed to select my brand account, by the way.) That is much more complicated. I hope it is easier with Google Apps Script, but I cannot get any update script running for my brand account.
I also tried to change the GCP project of the script from the default one to a dedicated one. This didn't fix the issue either.
I retried several times, also in Incognito.
Screenshots
Sorry, they are in German, but I think it is better to include them nevertheless.
From it seems like the script has been authorized:
Yet, the console throws an error: