Youtube API to count Subscribers , Views and Video using JavaScript

Learn to create a dashboard using YouTube API and JavaScript.

we can make a simple YouTube analytics and counter dashboard using YouTube API.

Its provides very decent documentation to integrate with JavaScript and in this application,
you don’t need to make any special environment to run this code.

so we are only using the basic features of HTML and JavaScript and the YouTube API.

You have to do two things to make this happen first create a YouTube API key from the Google developer console and get your channel ID.

You can find your channel ID in your YouTube studio but if you are going to check someone else channel you can choose any of the services available for extracting YouTube channel ID from YouTube channel link you can use any of that services to find any channels user ID.

So we are going to make a javascript for getting the youtube channel subscriber count, total video views count and total videos count. so we need an API key for that ..

https://console.developers.google.com/   Go to this website Create a project ->

the click library  -> search for YouTube Data API v3 ->

then Enable it  -> then click create credentials -> select Credential Type Public -> and get the api key

now get your channel ID  and start coding

Here is the code

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>YouTube API</title>
</head>
<body>
    YouTube Subscribers
    <div id="subscriberCount"></div>

    YouTube Video Views
    <div id="viewCount"></div>

    YouTube Video Count
    <div id="videoCount"></div>

    <script>

    
    const APIKey = 'Your API Key here';
    const Userid = 'Your Channel ID here';
    const subscriberCount= document.getElementById('subscriberCount');
    const viewCount = document.getElementById('viewCount');
    const videoCount = document.getElementById('videoCount');

   

    let getdata = () => {

        fetch(`https://www.googleapis.com/youtube/v3/channels?part=statistics&id=${Userid}&key=${APIKey}`)
        .then(response => {
            return response.json()
        })
        .then(data => {
            console.log(data);
            subscriberCount.innerHTML = data["items"][0].statistics.subscriberCount;
            viewCount.innerHTML = data["items"][0].statistics.viewCount;
            videoCount.innerHTML = data["items"][0].statistics.videoCount;
            
        })

    }

   getdata();
    </script>
</body>
</html>

 

Download Source Code : 



if you’re having any doubts about creating the API key from Google developer console or integrating the codes,

don’t worry I already made add detailed video about implementing the YouTube API with JavaScript and HTML.

so you can find all the informations and all the details in the video.

if you are interested to learn more about web development you can let me know in the comments and please suggest some topic to write or create videos.

 

Check out my other javascript tutorials here

check out tutorial video

 

 

Thank you, everyone. hope this helps

How to get the Youtube channel data

We are using google API to get the Youtube channel Data

Is google API is free ?

Yes, if you are using it for basic purposes.

What datas i can get from Youtube API

  • Subscribers Count
  • Videos Count
  • Video Views Count

Which is the latest Youtube API version

YouTube Data API v3

Post Your Questions on our forum

Post a question on Forum

Ajith Jojo Joseph

Self taught, dedicated young entrepreneur with many licensed products under his sleeve. Passionate about technology, business and excellence in general.

Share with your friends:

Comments are closed.

Export html table to excel, pdf, csv format using Datatable

Do you know how to export html table to excel, pdf, CSV, or excel format using Datatable? If you don’t […]

August 4, 2022

Instagram Hashtag API PHP and JavaScript Integration with RapidAPI

Do you know how to integrate Instagram Hashtag API with your website? In this tutorial, I will show you how […]

August 2, 2022

How to host React Application into Cpanel – Routes not working Htaccess fix

Do you know how to host react applications into Cpanel? After building your react application. you will get an index.html […]

July 28, 2022

How to get user Public IP Address using Javascript

Do you know how to get the user IP address using javascript? I will show you how. Today we are […]

July 27, 2022

Digital Marketing Toolkit

Get Free Access to Digital Marketing Toolkit. You can use all our tools without any limits

Get Free Access Now