3.7 KiB
3.7 KiB
YouTube Data API Setup Guide
This guide provides step-by-step instructions for setting up YouTube Data API integration for managing video comments.
Table of Contents
- Overview
- Prerequisites
- Google Cloud Console Setup
- Environment Configuration
- OAuth Redirect URI Configuration
- Permissions & Scopes
- Development vs Production
- Troubleshooting
Overview
API Version: YouTube Data API v3
API Service Name: youtube
API Version: v3
Auth Method: OAuth 2.0
Features Supported
- Fetch channel videos
- Read video comments
- Reply to comments
- Automatic token refresh
Prerequisites
- A Google account with a YouTube channel
- Access to Google Cloud Console
- Videos uploaded to your YouTube channel
Google Cloud Console Setup
Step 1: Create a New Project
- Navigate to Google Cloud Console
- Click on the project selector dropdown at the top
- Click "New Project"
- Enter project details:
- Project Name: e.g., "PX360 YouTube Integration"
- Organization: Select your organization (if applicable)
- Click "Create"
- Select your new project
Step 2: Enable YouTube Data API
- Go to "APIs & Services" → "Library"
- Search for "YouTube Data API v3"
- Click on it and click "Enable"
Step 3: Configure OAuth Consent Screen
- Go to "APIs & Services" → "OAuth consent screen"
- Select "External" user type (unless you have a Google Workspace account)
- Click "Create"
- Fill in the required fields:
- App Name: Your application name
- User Support Email: Your support email
- App Logo: Upload your logo
- Application Home Page: Your website URL
- Authorized Domains: Your domain(s)
- Developer Contact Email: Your email
- Click "Save and Continue"
- Add scopes (click "Add or Remove Scopes"):
https://www.googleapis.com/auth/youtube.readonlyhttps://www.googleapis.com/auth/youtube.force-ssl
- Click "Save and Continue"
- Add test users (for development)
- Click "Save and Continue"
Step 4: Create OAuth 2.0 Credentials
- Go to "APIs & Services" → "Credentials"
- Click "Create Credentials" → "OAuth client ID"
- Select "Web application"
- Configure:
- Name: e.g., "PX360 YouTube Client"
- Authorized JavaScript origins:
- Development:
http://127.0.0.1:8000 - Production:
https://yourdomain.com
- Development:
- Authorized redirect URIs:
- Development:
http://127.0.0.1:8000/social/callback/YT/ - Production:
https://yourdomain.com/social/callback/YT/
- Development:
- Click "Create"
- Download the JSON file - This is your credentials file
Step 5: Save Credentials File
- Rename the downloaded JSON file to
yt_client_secrets.json - Place it in your project's
secrets/directory:your_project/ ├── secrets/ │ ├── gmb_client_secrets.json │ └── yt_client_secrets.json └── ...
The JSON file structure:
{
"web": {
"client_id": "xxxxx.apps.googleusercontent.com",
"project_id": "your-project-id",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_secret": "your-client-secret",
"redirect_uris": ["http://127.0.0.1:8000/social/callback/YT/"]
}
}