MALE SPEAKER: In this tutorial, we're going to show
you how to obtain a refresh token for testing your code
without having to write the code to handle the
authorization flow yourself.
The first thing you'll want to do is [? browse to the ?]
OAuth Playground.
The OAuth Playground is a tool hosted on Google Developers
site that lets developers see authorization flow
step-by-step and see how API calls are
made at the HTTP layer.
You can find the OAuth Playground at developers.googl
e.com/oauthplayground or by searching for OAuth Playground
in your favorite search engine.
For today's tutorial, we're only going to show the steps
required to obtain a long-lived refresh token that
we can exchange for access tokens to make YouTube Data
API and YouTube Analytics API calls.
The first thing we need to do is configure the OAuth
Playground to use our client secret and client ID.
Let's find our client ID and client secret from the Google
API Console.
We're going to need these in a second.
Browse back through OAuth Playground and click the
Settings button.
Let's check the box using Use Your Own OAuth Credentials.
And let's make sure the access type is set to Offline,
because this is what we need to ensure that we receive a
long-lived refresh token and not a
short-lived access token.
You'll be presented with two fields, one for client ID and
one for client secret.
Let's copy-paste the values over from the API console.
There's one more thing we need to set up.
Note that we have a redirect URI set up that points to
developers.googl e.com/oauthplayground.
This is important because the OAuth Playground requires us
to redirect back through Playground after an
authorization step.
Let's click on Edit Settings.
If we haven't set this yet, let's enter this into the
Authorized Redirect URIs box and click Update.
Now let's go back through OAuth 2.0 Playground.
Let's select the APIs to authorize.
Scrolling down, we're going to select the YouTube Analytics
API, a read-only scope, and the YouTube Data API v3.
Now let's click Authorize APIs.
We'll be forwarded to a page where we'll
need to grant access.
If we're in charge of multiple channels, we'll first be
presented with an account picker.
Let's click Accept and continue.
We now have an authorization code, which we can use to
exchange for a refresh token and access token.
Let's click Exchange Authorization Code for Tokens.
The OAuth 2.0 Playground will populate the refresh token and
access token fields after making the API call.
We can start using these immediately.
But the value we want [? to save for our ?]
scripts is in the refresh token field.
As we can see, the access token will expire
in about one hour.
The official Google API clients will all handle
obtaining an access token for us as long as we supply a
client ID, client secrets, and refresh token.
And that's how we generate a refresh token using the OAuth
Playground.