A shields.io API for your youtube channel to protect your api key.
- Why
- Features
- Examples
- Configuration
- Getting a google api key & activate youtube api
- Find your youtube channel id
- Deployment
- Step by Step
- Usage
You can't publicly access the google/youtube api without an api key. That's why there is no shields.io badge for youtube channels. This repo aims to be the solution to this, because you deploy your own public api which only fetches your channel.
- Cache time to prevent rate limiting
- Secure api key due env variable
Name | Examples |
---|---|
plastic | |
flat | |
flat-square | |
for-the-badge | |
social |
All examples are live and based on my youtube channel: ntec.io
Variable Name | Description | Required |
---|---|---|
API_KEY | Your google api key. See section below on how to get one | TRUE |
CHANNEL_ID | The youtube channel id of which the stats should be processed | TRUE |
CACHE_TIME | Time in seconds on how long the last result is cached. Default is 300. | FALSE |
-
Go to google developer console
-
Log In to your google account
-
Click on Select a project (Looks like a dropdown button)
-
Create a new project by clicking on the New Project button
-
Give your project a name (or leave it to the generated one) and create your project by pressing on CREATE
-
On the next window, click on + ENABLE APIS AND SERVICES in the top
-
Search for Youtube in the search bar and click on YoTube Data API v3
-
Enable the API by clicking on ENABLE
-
Click on the 3 lines in the top left corner to open the side menu and hover over APIs & Services and then click on Credentials
-
Click on CREATE CREDENTIALS and then on API key
-
Copy your API key
-
Goto your advanced account settings
-
Copy your channel id
It is neccessary to deploy this repo by yourself to get a domain for the desired youtube channel. An easy and free way to deploy this repo is by using vercel. Just use the button below.
-
Click on the deploy button above or click here
-
Click on Continue
-
Click on no
-
Select your user account and click on continue
-
Fork the repo with a click on continue
-
Click again on Continue
-
Enter your API_KEY, CHANNEL_ID and CACHE_TIME. Check Configuration if you need help getting those things.
-
Click on Deploy and your deployment should finish after a short time
-
Deploy the repo and get your url from domains
Example in vercel:
-
Go to shields.io/endpoint and scroll down
-
Add your vercel url to the url field
-
Add your wanted url suffix:
-
to get the subscriber count: add api/subscriber
-
to get the view count: add api/views
-
to get the comment count: add api/comments
-
to get the video count: add api/videos
It should look like this:
-
-
Override the labels/colors/logo if you want (optional)
-
Click on the button to copy the badge url
-
Enjoy! :)