azad education azad education

The next-generation blog, news about technology.

India (HQ)

[email protected]

Full YouTube API Tutorial get channel data

azad education
Azad Education Dec 02, 2022 · 12 min read
Full YouTube API Tutorial get channel data

YouTube API Tutorial Get Data from youtube.

You Tube Data API get list

1. Subscriber's count

2. Views Count.

3. Get All Video's ID

4. Get YouTube Video Comment's.

5. Get YouTube Video Thumbnail.

6. Get Perticular video full information.

 

How to create api for getting  youtube channel information?

If we don't have project on google cloud before you must be create a project then follow these step for api creation.

We need to create API key for getting youtube channel information.

login to your gooogle account then go to https://console.cloud.google.com/apis/dashboard

Click on Enable APIS AND SERVICES

Enable YouTube Data API & Reporting API.

Go Back and click on credentials from left side menu bar. Now click on create credentials and select api key this will be create api keys for our project.

1. YouTube Channel get subscriber's and view's count from the youtube API

Note: all of curl url that can be check in browser directly.

https://www.googleapis.com/youtube/v3/channels?part=statistics&id=youtube_channel_id&key=api_key

JavaScript code to store to get data in variable.

  $.getJSON(

                'https://www.googleapis.com/youtube/v3/channels?part=statistics&id=youtube_channel_id&key=api_key',

                function(data) {

                    subscribers = data.items[0].statistics.subscriberCount;

                    views = data.items[0].statistics.viewCount;

                });

2. YouTube Channel get all video list.

https://www.googleapis.com/youtube/v3/search?key=api_key&channelId=youtube_channel_id&part=id&&maxResults=100&format=json

Note: This will return 100 Video information one time. You can chnage according to your requirment's.

JavaScript code to store only video id in array.

 let YouTube= [];

            $.getJSON('https://www.googleapis.com/youtube/v3/search?key=api_key&channelId=youtube_channel_id&part=id&&maxResults=100&format=json',

                function(res) {

                    res.items.forEach(element => {

                        if (element.id.videoId != "" && element.id.videoId != 'undefined')

                            YouTube.push(element.id.videoId);

                    });

                });

3. YouTube Channel get Video Comment's.

 

https://www.googleapis.com/youtube/v3/commentThreads?key=api_key&textFormat=plainText&part=snippet&videoId=Video_ID'&maxResults=50

Java Script code to geeting data in json format.

    $.getJSON(

                    'https://www.googleapis.com/youtube/v3/commentThreads?key=AIzaSyDEpB5ADO9LICqePCcnk1rjx-PSKA5rsos&textFormat=plainText&part=snippet&videoId=' +

                    videoId + '&maxResults=50',

                    function(data) {

                        data.items.forEach((video, index) => {

                            commentData[index] = {

                                comment: video.snippet.topLevelComment.snippet.textDisplay,

                                author: video.snippet.topLevelComment.snippet.authorDisplayName,

                                profile: video.snippet.topLevelComment.snippet.authorProfileImageUrl,

                                created: video.snippet.topLevelComment.publishedAt

                            }

                            allVideoComment[videoId] = commentData;

                        });

                    });

4. How do I get a YouTube video thumbnail from the YouTube API?

Each YouTube video has four generated images. They are predictably formatted as follows:

https://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg

The first one in the list is a full size image and others are thumbnail images. The default thumbnail image (i.e., one of 1.jpg2.jpg3.jpg) is:

https://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg

For the high quality version of the thumbnail use a URL similar to this:

https://img.youtube.com/vi/<insert-youtube-video-id-here>/hqdefault.jpg

There is also a medium quality version of the thumbnail, using a URL similar to the HQ:

https://img.youtube.com/vi/<insert-youtube-video-id-here>/mqdefault.jpg

For the standard definition version of the thumbnail, use a URL similar to this:

https://img.youtube.com/vi/<insert-youtube-video-id-here>/sddefault.jpg

For the maximum resolution version of the thumbnail use a URL similar to this:

https://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg

However, not every YouTube video contains all nine thumbnails. Also, the thumbnails' image sizes depends on the video (the numbers below are based on one). There are some thumbnails guaranteed to exist:

Width | Height | URL
------|--------|----
120   | 90     | https://i.ytimg.com/vi/<VIDEO ID>/1.jpg
120   | 90     | https://i.ytimg.com/vi/<VIDEO ID>/2.jpg
120   | 90     | https://i.ytimg.com/vi/<VIDEO ID>/3.jpg
120   | 90     | https://i.ytimg.com/vi/<VIDEO ID>/default.jpg
320   | 180    | https://i.ytimg.com/vi/<VIDEO ID>/mq1.jpg
320   | 180    | https://i.ytimg.com/vi/<VIDEO ID>/mq2.jpg
320   | 180    | https://i.ytimg.com/vi/<VIDEO ID>/mq3.jpg
320   | 180    | https://i.ytimg.com/vi/<VIDEO ID>/mqdefault.jpg
480   | 360    | https://i.ytimg.com/vi/<VIDEO ID>/0.jpg
480   | 360    | https://i.ytimg.com/vi/<VIDEO ID>/hq1.jpg
480   | 360    | https://i.ytimg.com/vi/<VIDEO ID>/hq2.jpg
480   | 360    | https://i.ytimg.com/vi/<VIDEO ID>/hq3.jpg
480   | 360    | https://i.ytimg.com/vi/<VIDEO ID>/hqdefault.jp

How to make auto youtube  subscription link?  

do follow the steps for gaining subscribers.

  1. Just go to your YouTube channel
  2. Past this code at the end of URL of your YouTube channel

“?sub_confirmation=1”

3. Then copy complete link

4. Go to any link shortened URL or you can google.

5. Paste complete link of YouTube channel and along with above bold text to shortened.

6. Share this link instead sharing whole link.

 

avatar

Azad Mohammed

An editor at AzadEducation
View Articles

I'am Azad, These blogs, tech skills and programing news, I am sharing with my exprience. I have 4+ year experiece in the web development. Also we are learning investing ideas. I believe in "big mind big dream", that will convert in smart mind. You can follow me on Linkedin profile.

Categories
C#
10
Java Script
8
SEO
4
Quick Hack Solution Tips
4

Subscribe to our mailing list!

We don't spam