Connecting a YouTube channel with OAuth (and fixing redirect_uri_mismatch)

Create the Google OAuth client, register the one redirect URI that works, connect a channel through the consent popup and understand the errors you may see along the way.

By YouTubeVision AI Team · · 4 min read

YouTubeVision AI uploads with the YouTube Data API v3 and OAuth 2.0. You configure one OAuth client once, then connect as many channels as you like; each channel keeps its own encrypted refresh token. Until you do this, the seeded simulated channel lets you test everything without contacting YouTube.

1. Prepare the Google Cloud project

  1. Create a dedicated project in the Google Cloud console. Quota, audit status and the consent screen are all per project.
  2. Enable the YouTube Data API v3.
  3. Configure the OAuth consent screen. Choose External (or Internal if every channel belongs to your Workspace organisation) and add your domain to the authorised domains.
  4. While the app is in Testing, add the Google account that owns or manages each channel as a test user.
  5. Add the three scopes the application requests:
https://www.googleapis.com/auth/youtube.upload
https://www.googleapis.com/auth/youtube.readonly
https://www.googleapis.com/auth/youtube.force-ssl

The upload scope is required. Without it the channel ends up in the MissingScopes state.

2. Create the OAuth client and the redirect URI

Create an OAuth client of type Web application. The one field that causes most trouble is the Authorized redirect URI. It must be exactly:

https://<your-host>/api/v1/channels/oauth/callback

where <your-host> is the public host name of your site. It must match character for character: scheme, host, port and path, with no trailing slash.

Fixing Error 400: redirect_uri_mismatch

Google shows redirect_uri_mismatch when the URI your installation sends is not in the client's list. The fix is always to make the two values identical:

  • Register the callback endpoint above, not a dashboard page such as /app/, and not a value copied from Google's error page.
  • Use the same scheme and port you actually browse with. http is only acceptable for local development.
  • Remove any trailing slash.
  • Remember that changes in the Google console can take a few minutes to apply.

The Providers page shows the exact value for the address you are using, with a copy button, and rejects any other path. For local development, register the local callback address you actually use as well.

3. Enter the client in YouTubeVision AI

On Providers, open YouTube Data API v3 (you need the providers.manage permission) and set the settings JSON:

{
  "clientId": "<client id>.apps.googleusercontent.com",
  "redirectUri": "https://<your-host>/api/v1/channels/oauth/callback",
  "chunkSizeMb": 8
}

Do not put the client secret in the JSON; it is rejected there. Use Set secret instead, then Enable the provider and run Check.

4. Connect a channel through the popup

  1. Create the channel with publishing provider youtube and a default privacy of Private for your first tests.
  2. Open the channel and choose Connect (permission channels.authorize).
  3. Google's consent screen opens in a popup window. If your browser blocks popups, the current tab navigates instead.
  4. Sign in with the account that manages the channel, pick the brand account if asked, and keep the upload permission checked.
  5. Google redirects to the callback, the API stores the encrypted tokens and the popup reports back to the dashboard, which opens the channel. The popup closes itself where the browser allows it.

The signed state value in the request expires after 15 minutes, so finish the consent within that time.

Errors you might see

  • youtube.not_configured: the client id, redirect URI or secret is missing.
  • youtube.redirect_uri: the configured redirect URI is not this app's callback endpoint.
  • channel.not_youtube: the channel still uses the simulated publisher.
  • oauth.wrong_channel: you signed in to a different channel than the one this record is bound to.
  • oauth.no_refresh_token: Google had already issued a token to this app. Remove the app's access in your Google account permissions, then connect again.

Testing mode and refresh tokens

For an External app in Testing, Google's refresh tokens expire after 7 days. The channel is then marked Revoked and an alert asks you to reconnect. Move the app to production for unattended operation, and plan for Google's verification if you will connect channels owned by other people.

Also note that videos uploaded by API projects that have not passed YouTube's compliance audit stay private. YouTubeVision AI reads the real privacy back after each upload and warns you, which is one more reason to start with private drafts. More on that in AI disclosure and safe-by-default publishing.

Related posts