Generate a token for Youtube Data API

This post is an additional resouce to my course All about NextJS.

Activating your Google Developers console

When logged in to your Google Account (there is no way of getting a token without one). Visit Google Developers Console and get your account activated as a developer account.

Next, we will register our application. There are 2 types of credentials: OAuth 2.0, and API keys. In this post, I will show you how to use API keys.

Registering App

Now that you are in your Google Developer Dashboard, go to credentials and you should see something similar to the image below click on Create Credentials and select API key

google developers dashboard: credentials tab

A dialog will pop-up with the key. At this point, you can copy your key already, but do not go away, your credentials aren‘t registered and saved just yet. Click on restrict key.

Restricting your token

Everything you do from now on is optional as long as you click on the save button at the bottom once you‘re there the first time. But there are some best practices that are worth pointing out:

  1. Name your key accordingly (not like I did in the screenshot above!). I suggest a name that reflects the app which is going to use it, or the reason why you created the key. Your future-self will appreciate it.

  2. Set some application restriction: your key has a quota, and restricting its usage based on app, IP, or domain will safe-guard you from someone else spending it.

Done

As I said, once you finish, hit save. Your key is now created and you can go back to your code!

Reference docs