Skip to main content
This guide walks you through the complete YouTube API setup process, from creating credentials to authenticating your channel.

Prerequisites

Before starting, ensure you have:
You must be the owner or have manager permissions on the YouTube channel to authorize the application.

Step 1: Create Google Cloud Project

1

Open Google Cloud Console

2

Create New Project

  1. Click the project dropdown at the top
  2. Click “New Project”
  3. Enter project details:
    • Project name: YouTube Automation Agent
    • Organization: Leave default or select your organization
  4. Click “Create”
3

Wait for Project Creation

The project will be created in a few seconds. You’ll see a notification when it’s ready.

Step 2: Enable YouTube APIs

1

Navigate to APIs & Services

  1. Select your project from the dropdown
  2. Click on the hamburger menu (☰)
  3. Go to “APIs & Services”“Library”
2

Enable YouTube Data API v3

  1. Search for “YouTube Data API v3”
  2. Click on it
  3. Click “Enable”
This API is required for uploading videos, managing playlists, and accessing channel information.
3

Enable YouTube Analytics API

  1. Search for “YouTube Analytics API”
  2. Click on it
  3. Click “Enable”
This API provides access to video performance metrics and analytics data.

Before creating credentials, you must configure the OAuth consent screen:
1

Navigate to OAuth Consent Screen

Go to “APIs & Services”“OAuth consent screen”
2

Select User Type

Choose “External” and click “Create”
  • Internal: Only for Google Workspace organizations
  • External: For personal accounts and general use (choose this)
3

Fill App Information

App name: Your channel name or “YouTube Automation Agent”User support email: Your email addressApp logo: (Optional) Upload your channel logoApplication home page: (Optional) Your website or channel URLDeveloper contact information: Your email address
4

Configure Scopes

  1. Click “Add or Remove Scopes”
  2. Add these YouTube scopes:
https://www.googleapis.com/auth/youtube.upload
https://www.googleapis.com/auth/youtube
https://www.googleapis.com/auth/youtube.readonly
https://www.googleapis.com/auth/yt-analytics.readonly
  • youtube.upload - Upload videos
  • youtube - Manage videos and channel
  • youtube.readonly - Read channel information
  • yt-analytics.readonly - Access analytics data
  1. Click “Update”
5

Add Test Users (Optional)

While in development/testing mode, add your Google account email as a test user.
In testing mode, only test users can authorize the app. For production use, you’ll need to submit for verification.
6

Review and Save

Review your settings and click “Save and Continue” through all screens.

Step 4: Create OAuth 2.0 Credentials

1

Navigate to Credentials

Go to “APIs & Services”“Credentials”
2

Create OAuth Client ID

  1. Click ”+ Create Credentials”
  2. Select “OAuth client ID”
3

Configure Application Type

Application type: Select “Web application”Name: YouTube Automation OAuth Client
4

Add Authorized Redirect URIs

Under “Authorized redirect URIs”, add:
http://localhost:8080/oauth2callback
The redirect URI must match exactly what’s configured in your application. Port 8080 is the default.
If you’re running on a different port, update accordingly:
http://localhost:YOUR_PORT/oauth2callback
5

Create and Download

  1. Click “Create”
  2. A dialog will show your Client ID and Client Secret
  3. Click “Download JSON” or copy the credentials

Step 5: Configure Application

Now add the credentials to your application:
Create or edit config/credentials.json:
config/credentials.json
{
  "youtube": {
    "client_id": "123456789-abcdefg.apps.googleusercontent.com",
    "client_secret": "GOCSPX-abc123def456",
    "redirect_uris": [
      "http://localhost:8080/oauth2callback"
    ]
  },
  "channel": {
    "channelName": "Your Channel Name",
    "channelDescription": "Your channel description",
    "defaultCategory": "24",
    "defaultPrivacy": "public",
    "websiteUrl": "https://yourwebsite.com",
    "businessEmail": "your@email.com"
  }
}

Step 6: Authenticate Your Channel

Now authenticate the application with your YouTube channel:
1

Run Authentication

node authenticate.js
Or use the setup command:
npm run setup
2

Authorization URL

The console will display an authorization URL:
🔗 Please visit this URL to authorize the application:
https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&scope=...
Copy and open this URL in your browser.
3

Grant Permissions

  1. Sign in with your Google account (if not already signed in)
  2. Select the YouTube channel to authorize
  3. Review the requested permissions:
    • Upload videos
    • Manage your YouTube account
    • View YouTube Analytics reports
  4. Click “Allow”
If you see a “This app isn’t verified” warning, click “Advanced”“Go to [App Name] (unsafe)”. This is normal for apps in testing mode.
4

Copy Authorization Code

After granting permissions, you’ll see an authorization code or be redirected to localhost:8080.If shown a code:
  1. Copy the code
  2. Paste it into the terminal when prompted
If redirected:
  1. The application will automatically capture the code
  2. Authentication will complete automatically
5

Verify Success

You should see:
✅ YouTube authentication completed!
✅ Tokens saved to config/tokens.json

Step 7: Verify Configuration

Test that everything is working:
1

Run Test Script

npm test
This will verify:
  • YouTube API connection
  • Channel access
  • Upload permissions
  • Analytics access
2

Check Channel Info

The test should output your channel information:
✅ Connected to channel: Your Channel Name
📊 Subscriber count: 1,234
🎬 Total videos: 56
👁️  Total views: 123,456

Channel Configuration

Configure channel-specific settings in config/credentials.json:
{
  "channel": {
    "channelName": "Your Channel Name",
    "channelDescription": "Description of your channel",
    "defaultCategory": "24",
    "defaultPrivacy": "public",
    "websiteUrl": "https://yoursite.com",
    "businessEmail": "business@email.com"
  },
  "content": {
    "contentTypes": ["tutorial", "explainer", "story"],
    "competitorChannels": [],
    "targetAudience": "Tech enthusiasts aged 18-35",
    "postingFrequency": "daily",
    "preferredPostTime": "14:00"
  }
}

Video Category IDs

IDCategory
1Film & Animation
2Autos & Vehicles
10Music
15Pets & Animals
17Sports
19Travel & Events
20Gaming
22People & Blogs
23Comedy
24Entertainment
25News & Politics
26Howto & Style
27Education
28Science & Technology
29Nonprofits & Activism

Privacy Settings

Recommended for: Growth-focused channels
  • Appears in search results
  • Recommended to viewers
  • Counts toward watch time
  • Eligible for monetization

Content Strategy Configuration

Configure what types of content to generate:
{
  "content": {
    "contentTypes": [
      "tutorial",
      "explainer",
      "list",
      "story",
      "review"
    ],
    "competitorChannels": [
      "UCxxxxxxxxxxxxxx",
      "UCyyyyyyyyyyyyyy"
    ],
    "targetAudience": "Tech enthusiasts interested in AI and automation",
    "postingFrequency": "daily",
    "preferredPostTime": "14:00"
  }
}

Content Types

Tutorial

Step-by-step instructional videos teaching specific skills or processes.

Explainer

Educational content explaining concepts, technologies, or phenomena.

List

Top 10, best of, or compilation-style videos (e.g., “5 Ways to…”).

Story

Narrative-driven content with storytelling elements.

Review

Analysis and opinions on products, services, or content.

Posting Schedule

Configure automated posting:
{
  "content": {
    "postingFrequency": "daily",
    "preferredPostTime": "14:00",
    "timezone": "America/New_York"
  }
}

Frequency Options

ValueDescription
dailyOne video per day
every-2-daysEvery other day
3-per-weekThree times per week
weeklyOnce per week
customDefine custom cron schedule

Best Posting Times

US Audience:
  • 12:00 PM - 4:00 PM EST (lunch/afternoon)
  • 7:00 PM - 10:00 PM EST (evening)
European Audience:
  • 2:00 PM - 4:00 PM CET
  • 8:00 PM - 10:00 PM CET
Global Audience:
  • 1:00 PM - 3:00 PM UTC
The system will analyze your channel’s analytics to recommend optimal posting times after collecting sufficient data.

Token Refresh

OAuth tokens expire periodically. The system automatically refreshes them:
// Automatic refresh logic
if (tokens.expiry_date < Date.now()) {
  const { credentials } = await oauth2Client.refreshAccessToken();
  oauth2Client.setCredentials(credentials);
  await saveTokens(credentials);
}
If you see authentication errors, the refresh token may be invalid. Re-run authentication:
node authenticate.js

Quota Management

YouTube API has daily quota limits:
  • Default quota: 10,000 units/day
  • Upload video: 1,600 units
  • Update video: 50 units
  • List videos: 1 unit

Monitor Usage

Check quota usage in Google Cloud Console:
  1. Select your project
  2. Navigate to “APIs & Services”“YouTube Data API v3”
  3. Click “Quotas”

Request Quota Increase

If you need more quota:
  1. Go to “IAM & Admin”“Quotas”
  2. Filter for “YouTube Data API v3”
  3. Select the quota to increase
  4. Click “Edit Quotas”
  5. Fill out the request form
Quota increases are usually approved within 24-48 hours for reasonable requests.

Troubleshooting

Solution:
  1. Check that redirect URI in code matches Google Cloud Console exactly
  2. Ensure there are no trailing slashes or typos
  3. Verify the port number matches
Update in Google Cloud Console:
  • Go to Credentials → OAuth 2.0 Client IDs
  • Edit your client
  • Update redirect URIs
Solution:
  1. Ensure YouTube Data API v3 is enabled in your project
  2. Wait a few minutes after enabling APIs
  3. Clear browser cache and try again
Solution:
  1. Verify client_id and client_secret are correct
  2. Check for extra spaces or line breaks when copying
  3. Re-download credentials JSON from Google Cloud Console
Solution:Re-authenticate:
rm config/tokens.json
node authenticate.js
Solution:
  1. Wait until quota resets (daily at midnight Pacific Time)
  2. Reduce upload frequency
  3. Request quota increase
  4. Use GLOBAL_RATE_LIMIT_PER_HOUR to throttle requests

Security Best Practices

Protect Credentials

  • Never commit credentials.json or tokens.json to git
  • Add to .gitignore
  • Use environment variables in production

Rotate Keys

  • Regenerate OAuth credentials every 6 months
  • Delete old unused credentials
  • Use different credentials for dev/prod

Limit Scopes

  • Only request necessary OAuth scopes
  • Review permissions periodically
  • Revoke unused authorizations

Monitor Access

  • Check authorized apps in Google Account settings
  • Enable 2FA on Google account
  • Review API access logs

Next Steps

Your YouTube configuration is complete! Now you can:

Start the Agent

Launch the YouTube Automation Agent and start generating content

Configure Agents

Customize the specialized AI agents for your channel