Docs / Stackposts

YouTube API Official

Please follow this guide

Estimated reading: 5 minutes

YouTube Post API Official Configuration Guide

This guide explains how to configure the official YouTube Data API for StackPosts YouTube video publishing. It covers Google Cloud setup, OAuth consent screen, OAuth credentials, YouTube scopes, callback URL, channel connection, video upload testing, quota notes, and common troubleshooting.

What This Integration Does

  • Connect YouTube channels using Google OAuth 2.0.
  • List authorized YouTube channels from the connected Google account.
  • Publish one video file to a selected YouTube channel.
  • Set video title, description, category, privacy, tags, and optional thumbnail.
  • Refresh OAuth access tokens automatically using the stored refresh token.

Official APIs Used

Purpose API / Endpoint
OAuth Authorization https://accounts.google.com/o/oauth2/v2/auth
OAuth Token Exchange https://oauth2.googleapis.com/token
List Channels GET https://www.googleapis.com/youtube/v3/channels
Upload Video POST https://www.googleapis.com/upload/youtube/v3/videos
Set Thumbnail POST https://www.googleapis.com/upload/youtube/v3/thumbnails/set

Requirements

  • A Google account with access to Google Cloud Console.
  • A YouTube channel for testing and production use.
  • A public domain with HTTPS enabled.
  • Admin access to StackPosts integration settings.
  • YouTube Data API v3 enabled in the Google Cloud project.

Important: Service accounts are not suitable for normal YouTube channel video publishing. YouTube channel publishing requires user OAuth consent.

Step 1: Create or Select a Google Cloud Project

  1. Open Google Cloud Console.
  2. Create a new project or select an existing project.
  3. Use a clear project name, for example StackPosts YouTube.
  4. Make sure the correct project is selected before enabling APIs or creating credentials.

Step 2: Enable Required APIs

Go to APIs & Services > Library and enable:

  • YouTube Data API v3 - required for channel connection, video upload, and thumbnail upload.
  • YouTube Analytics API - optional, only required if YouTube analytics sync is used.

Step 3: Configure OAuth Consent Screen

  1. Go to Google Auth Platform or APIs & Services > OAuth consent screen.
  2. Choose External if your users are outside your Google Workspace.
  3. Enter app name, user support email, developer contact email, homepage, privacy policy, and terms URLs.
  4. Add your production domain to Authorized domains.
  5. If the app is still in testing mode, add test Google accounts under Test users.

Step 4: Add OAuth Scopes

Minimum scopes for YouTube video publishing:

https://www.googleapis.com/auth/youtube
https://www.googleapis.com/auth/userinfo.email

Optional scope for YouTube Analytics:

https://www.googleapis.com/auth/yt-analytics.readonly

Request only the scopes that your installation uses. Sensitive scopes may require Google app verification before the integration can be used publicly.

Step 5: Create OAuth Client ID

  1. Go to APIs & Services > Credentials.
  2. Click Create Credentials > OAuth client ID.
  3. Select Web application.
  4. Add your production domain under Authorized JavaScript origins.
  5. Add the StackPosts callback URL under Authorized redirect URIs.

Production redirect URI:

https://your-domain.com/integrations/youtube/channel

Local development examples:

http://localhost/integrations/youtube/channel
http://127.0.0.1/integrations/youtube/channel

The redirect URI must match exactly, including http or https, domain, path, and trailing slash. A mismatch will cause the Google error redirect_uri_mismatch.

Step 6: Create API Key

  1. Go to APIs & Services > Credentials.
  2. Click Create Credentials > API key.
  3. Restrict the key where possible.
  4. For API restrictions, select YouTube Data API v3.

Step 7: Configure StackPosts

Open the StackPosts admin integration settings and configure YouTube:

Field Value
Status Enabled
Client ID OAuth Client ID from Google Cloud
Client Secret OAuth Client Secret from Google Cloud
API Key Google API key
Permissions OAuth scopes separated by spaces
Callback URL https://your-domain.com/integrations/youtube/channel

Recommended permissions for posting video:

https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/userinfo.email

Step 8: Connect a YouTube Channel

  1. Log in to StackPosts as a user allowed to connect channels.
  2. Open the Channels area.
  3. Select YouTube Channel.
  4. Click Connect.
  5. Choose the Google account that owns or manages the YouTube channel.
  6. Grant the requested permissions.
  7. Select the YouTube channel returned by Google.

Step 9: Publish a Test Video

  1. Select one connected YouTube channel.
  2. Upload exactly one video file.
  3. Enter a video title.
  4. Set category ID, for example 22.
  5. Choose privacy: public, unlisted, or private.
  6. Add comma-separated tags if needed.
  7. Add an optional thumbnail URL if needed.
  8. Publish the post and verify it in YouTube Studio.

Quota Notes

  • YouTube Data API quota is counted per Google Cloud project.
  • A video upload with videos.insert uses 100 quota units.
  • The default YouTube Data API quota is commonly 10,000 units per day, but it may vary by project.
  • Check quota usage in APIs & Services > Quotas.

Common Errors

Error Fix
redirect_uri_mismatch Copy the exact StackPosts callback URL into Google OAuth Client authorized redirect URIs.
access_denied Add the Google account as a test user or complete OAuth consent verification.
No channels returned Make sure the Google account has a YouTube channel and YouTube Data API v3 is enabled.
No refresh token Revoke the app from the Google account security page, then connect again.
Quota error Check YouTube Data API quota and reduce repeated upload tests.

Production Checklist

  • YouTube Data API v3 is enabled.
  • OAuth consent screen is fully configured.
  • Production domain is added to authorized domains.
  • OAuth Client ID type is Web application.
  • Redirect URI is exactly https://your-domain.com/integrations/youtube/channel.
  • Client ID and Client Secret are saved in StackPosts.
  • YouTube integration status is enabled.
  • Channel connection has been tested.
  • Private or unlisted video upload has been tested before public publishing.
  • Quota usage is monitored after upload tests.

Policy note: Some Google Cloud projects may need Google verification or YouTube API Services audit before public production use. In some cases, videos uploaded through unverified projects may be restricted.

Official Documentation