Building an AI agent or automated pipeline that generates, edits, and uploads videos to YouTube is a massive time-saver—until your pipeline silently crashes a week later with an invalid_grant error.
When you connect a personal script, n8n workflow, or custom YouTube agent to the YouTube Data API v3, Google puts your project in Testing mode by default. In Testing mode, Google kills your OAuth refresh token every 7 days.
If you want your YouTube agent to upload videos on autopilot without forcing you to manually re-authenticate every week, you have to push your app to Production. However, navigating between Google's developer tools—and dealing with hidden UI traps when you don't own a custom domain—trips up almost everyone on their first try.
Here is the complete breakdown of the two platforms you need to use, and every single caveat you need to bypass to keep your YouTube agent connected permanently.
First: Know the Difference Between the Two Tools
Before touching any settings, it helps to separate the two distinct Google tools involved in this setup:
-
Google Cloud Console (
://google.com): This is your control center and app registry. Here, you enable the YouTube Data API v3, generate your Client ID and Client Secret, define your app's branding, and control whether your app is in Testing or Production mode. -
Google OAuth 2.0 Playground (
://google.com): This is a temporary token-generator utility. Instead of writing a custom web server just to handle Google's login redirect once, you plug your Client ID and Client Secret into the Playground, log into your YouTube channel, and exchange the login permission for a Refresh Token that you can copy-paste into your AI agent.
Part 1: Prepare Your Agent in Google Cloud Console
To stop the 7-day token expiration, you must switch your app from Testing to In production inside the Google Cloud Console under Google Auth Platform > Audience.
Caveat 1: The Locked "Publish App" Button & The Branding Trap
When you open the Audience page, you will likely find the Publish app button disabled with this notice:
"To publish your app, you must complete your configuration on the Branding page."
If you jump over to the Branding page and leave the Authorized domains field blank—or leave an empty text input box open—Google blocks you with Invalid domain: must not be empty.
Even worse, Google's updated interface strictly requires an Application home page, a Privacy policy link, and at least one Authorized domain before unlocking the Publish button.
How to fix it without buying a domain:
Because this agent is strictly for your own YouTube channel, you do not need to buy a domain or build a website:
-
Use a free public URL: Create a public GitHub repository (e.g.,
https://github.com) or a public Google Doc stating that the app is a private automation tool for your personal channel. -
Fill out the Branding page:
- Application home page: Paste your GitHub repo or Google Doc URL.
-
Application privacy policy link: Paste a URL on that exact same root domain (e.g.,
https://github.com#privacy). -
Authorized domains: Click + Add domain and enter the matching root domain (
github.comorgoogle.com). (Tip: If you accidentally add a second empty domain row, click the trash can icon to delete it or the form won't save). - Terms of service link: Leave this completely blank—Google does not require it.
- Developer contact information: Enter your email address at the bottom and click Save.
Caveat 2: You Do NOT Need to Submit for Verification
Return to the Audience page and refresh the browser. The Publish app button will now be clickable. Click it and confirm.
Because uploading videos (youtube.upload) is classified as a sensitive scope, Google will immediately prompt you to Submit for verification with a warning about unverified apps.
Ignore and close this prompt.
- Your app status is already switched to In production.
- Google allows unverified production apps to serve up to 100 lifetime users without security audits or domain ownership checks—more than enough for your own channel(s).
(Note: If you happen to use a paid Google Workspace account rather than a standard @gmail.com account, you can avoid publishing altogether by setting your **User type* to Internal—Internal apps never expire refresh tokens).*
Part 2: Generate Your Permanent Token in OAuth 2.0 Playground
Now switch over to the Google OAuth 2.0 Playground (://google.com) to generate the actual credential your YouTube agent will use.
Caveat 3: Forgetting to Use Your Own Credentials
By default, the OAuth Playground uses Google's generic public Client ID, whose tokens expire within hours.
- Click the Gear icon (OAuth 2.0 configuration) in the top-right corner of the Playground.
- Check Use your own OAuth credentials.
- Paste the Client ID and Client Secret you created in the Google Cloud Console.
- Ensure Access type is set to Offline and Force prompt is set to Consent Screen.
Caveat 4: Confusing the Authorization Code with the Refresh Token
In Step 1 on the left sidebar, select the two scopes your YouTube agent needs to upload and edit videos:
https://googleapis.comhttps://googleapis.com
Click Authorize APIs. When you log in, Google will show a warning screen saying "Google hasn't verified this app." Click Advanced at the bottom left, then click Go to Your Agent Name.
Once redirected back to the Playground, look carefully at Step 2:
- The box labeled Authorization code (starting with
4/0A...) is NOT your refresh token. It is a single-use, temporary code that expires in minutes. - You must click the blue Exchange authorization code for tokens button.
- Look at the JSON response on the right. Copy the string next to
"refresh_token"(it always starts with1//). That is the permanent credential your agent needs.
Caveat 5: Old Refresh Tokens Still Die in 7 Days
This is the biggest trap of all: switching your app to "In production" does not retroactively save refresh tokens you generated while in Testing mode.
Refresh tokens inherit the publishing status of your Google Cloud project at the exact second they are created. If you generated a token before clicking Publish app, throw it away and generate a brand-new one in the Playground now.
How Long Will Your YouTube Agent Stay Connected?
Once you paste that production "refresh_token" into your YouTube agent's .env file or workflow manager, it will automatically fetch fresh 1-hour access tokens behind the scenes forever.
Google will only invalidate a production refresh token if:
- Your agent goes 6 consecutive months without uploading or making a single API request.
- You change your Google Account password or manually revoke the app's permissions in your Google Account security settings.
- You generate more than 100 refresh tokens for the exact same Client ID and Google Account (which silently revokes the oldest ones).
With those caveats cleared, your YouTube agent is ready to run hands-free!
Top comments (0)