Create OAuth tokens in Google Cloud to interact with the Youtube Data API
Before we start interacting with Google services through their API, e.g. Update a YouTube video's title, we first need to generate our OAuth tokens in Google Cloud.
Head over to Google Cloud Console to get started. You may need to sign in. You should eventually land on this page.
Once you arrive there, click on Select a project
and then New Project
.
Give your project a name and assign a location. I have left it as No organization
, then click Create
You'll be taken to the following screen. Click on Enabled APIs & Services under
APIs & Services`.
It will bring you to the following page. On that page, click on Enable APIs and Services
From there, let's search for YouTube Data API v3
. Click on that when it is displayed in the results.
Click Enable
.
You will be brought to the YouTube Data API v3
homepage. The API has been enabled but we also need to create our credentials i.e. The OAuth Tokens. Click on Create Credentials
.
There is a number of sections we need to go through to create our credentials. First, let set the data that we want to access as User data
. If it was public data, then we would simply need an API key.
After that, fill in your details under the OAuth Consent Screen
.
Then we have to add our scopes. This is the section where we tell Google what sections of the API we want to use. Click on Add or Remove Scopes
, and scroll across to the two that are selected in the image below. Select them.
Next, we need to fill the section under OAuth Client ID
. Let's select Web Application
for our application type, give our app a Name
, set our Authorized JavaScript Origins
, basically where our requests are coming from and our Authorized Redirect URIs
.
We can set the redirect to simply http://localhost:3000/callback
. We can then click Create
and it will go ahead and create our credentials.
It will give you your Client ID
, you will have to go ahead and click Download
, which will be a JSON object with all your tokens, including your Client secret
.
Finally, we need to add a test user. Back in Google Cloud, click on the OAuth consent
, then scroll down to Test User
and click Add Users
, and add in the email address of your gmail account.
And that is it! You have created your OAuth Tokens, in Google Cloud for the YouTube Data API.
About the Author
Open for work
Hi, I'm Ryan from Adelaide, South Australia.
I'm a web developer and computer science tutor. I also rock climb, play wheelchair basketball and brew beer.