I have been playing with the YouTube API for the last few days. One idea I had was to create an application that would show some basic information about YouTube channels. I’ve managed to create a simple app that exactly does that. Here, I’m presenting the demo version.
You may find the code source for the application here: https://github.com/NoToolsNoCraft/YouTube-Account-Checker
Explaining the application
The application I’m presenting here is basically accessing the Google API source code for YouTube that we may access using the link that we can see here:
https://www.googleapis.com/youtube/v3/channels?part=snippet,contentDetails,statistics&id=UC7nyL0_b70aZZ91nHlELNPw&key=(Add API key Here)
This link should be used to add the ID for the YouTube channel and the API key that was previously generated. If we do this in the browser properly, we will get results that will look like this:
So, in the first step, my application opens the source pages for each channel requested by its ID (or username). In the second step, it takes the information provided in this source and presents it in a more user-friendly way.
What should we type in the search bar
The app is set in a way that it accepts two forms of inputs:
- YouTube channel ID (for example: UC7nyL0_b70aZZ91nHlELNPw)
- YouTube channel username (for example: @kurcovizija)
To get a YouTube API key, follow these steps:
The API key for YouTube has to be generated here: https://console.cloud.google.com/
Step 1: Create a Google Cloud Project
- Go to the Google Cloud Console
- Sign in with your Google account if you haven’t already done so.
- Create a new project:
- Click on the project dropdown at the top of the page.
- Click “New Project”.
- Enter a project name and click “Create”.
Step 2: Enable YouTube Data API v3
- With your project selected, go to the API Library.
- Search for “YouTube Data API v3”.
- Click on “YouTube Data API v3”.
- Click “Enable”.
Step 3: Create API Credentials
- Go to the Credentials page
- Click “Create Credentials” and select “API key”.
- Your API key will be generated and displayed. Copy this key for use in your application.
Step 4: Restrict Your API Key (Optional but recommended)
- On the same Credentials page, find your newly created API key.
- Click on the pencil icon to edit the key.
- Under “Application restrictions”, select “HTTP referrers (web sites)”.
- Enter the URLs that will be allowed to use this API key.
- Under “API restrictions”, select “Restrict key” and choose “YouTube Data API v3”.
- Save your changes.
- Use Your API Key in Your Website
403 error – No more tokens
When the daily amount of requests is used, every click on the button (that interacts with the API source) will result in a 403 error. As soon as the daily requests (tokens) are reset, it will work properly again.