IntegrationsBeginner

How to Get a YouTube Data API Key and OAuth Credentials

Set up a Google Cloud project, enable the YouTube Data API v3, and create the OAuth client every automation in this series depends on.

9 minBeginner

Almost every YouTube automation that touches your own channel (uploading videos, editing titles, posting comments, pulling analytics) runs through the YouTube Data API v3, and that API needs an OAuth client tied to a Google Cloud project. This guide walks through that one-time setup so the rest of the integrations in this category just work.

What you need

  • A Google account that owns or manages the YouTube channel
  • A web browser (everything here is point and click in the cloud console)
  • About 10 minutes for the one-time setup

Step 1: Create a Google Cloud project

Open console.cloud.google.com, click the project dropdown in the top bar, then New Project. Give it a name like youtube-automation and create it. Wait for the notification that the project is ready, then make sure it is selected in the top bar.

Google Cloud Console — New Project
Project name: youtube-automation
Project ID: youtube-automation-481203 (auto)
Location: No organization
[ CREATE ] [ CANCEL ]
Naming the project before enabling any APIs.

Step 2: Enable the YouTube Data API v3

From the left menu choose APIs & Services, then Library. Search for YouTube Data API v3, open it, and click Enable. The API will not respond to any of your requests until this is switched on for the project.

Go to APIs & Services, then OAuth consent screen. Pick External, fill in an app name and your email, and add yourself as a Test user. While the app is in Testing mode only the test users you list can authorize it, which is exactly what you want for a personal automation.

Add the right scopes
Add the scope youtube.force-ssl so your token can read and write channel data (upload, comment, edit). The narrower youtube.readonly scope cannot post or upload.

Step 4: Create OAuth client credentials

Open APIs & Services, then Credentials, click Create Credentials, and choose OAuth client ID. For a script running on your own machine choose Desktop app. Download the resulting JSON file and keep it private, it is the key to your channel.

Credentials — OAuth client ID
Application type: ( ) Web application
(•) Desktop app
( ) Android
Name: yt-cli-client
[ CREATE ] then [ DOWNLOAD JSON ]
The Desktop app type is the simplest for local scripts.

Step 5: Verify the file

The downloaded file is usually named something like client_secret_xxxx.json. Rename it to client_secret.json and place it in your project folder. A quick peek confirms it has the fields scripts expect.

client_secret.json
{
  "installed": {
    "client_id": "4812....apps.googleusercontent.com",
    "project_id": "youtube-automation-481203",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token",
    "client_secret": "GOCSPX-....",
    "redirect_uris": ["http://localhost"]
  }
}
Mind the quotas
A new project gets 10,000 quota units per day. A read costs 1 unit, an upload costs about 1,600. Plan batch jobs around that ceiling rather than discovering it mid run.

Result

You now have an enabled YouTube Data API v3 and a client_secret.json holding your OAuth client. Every later guide that says assume you have your OAuth credentials is pointing back to this file.

Watch related tutorials

Tags
#youtube#google-cloud#oauth#api#setup