YouTube API to fetch all videos on a channel
Solution 1
You need to look at the YouTube Data API. You will find there documentation about how the API can be accessed. You can also find client libraries.
You could also make the requests yourself. Here is an example URL that retrieves the latest videos from a channel:
https://www.googleapis.com/youtube/v3/search?key={your_key_here}&channelId={channel_id_here}&part=snippet,id&order=date&maxResults=20
After that you will receive a JSON
with video ids and details, and you can construct your video URL like this:
http://www.youtube.com/watch?v={video_id_here}
Solution 2
First, you need to get the ID of the playlist that represents the uploads from the user/channel:
https://developers.google.com/youtube/v3/docs/channels/list#try-it
You can specify the username with the forUsername={username}
param, or specify mine=true
to get your own (you need to authenticate first). Include part=contentDetails
to see the playlists.
GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&forUsername=jambrose42&key={YOUR_API_KEY}
In the result "relatedPlaylists"
will include "likes"
and "uploads"
playlists. Grab that "upload"
playlist ID. Also note the "id"
is your channelID for future reference.
Next, get a list of videos in that playlist:
https://developers.google.com/youtube/v3/docs/playlistItems/list#try-it
Just drop in the playlistId!
GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&maxResults=50&playlistId=UUpRmvjdu3ixew5ahydZ67uA&key={YOUR_API_KEY}
Solution 3
Here is a video from Google Developers showing how to list all videos in a channel in v3
of the YouTube API.
There are two steps:
Query Channels to get the "uploads" Id. eg
https://www.googleapis.com/youtube/v3/channels?id={channel Id}&key={API key}&part=contentDetails
Use this "uploads" Id to query PlaylistItems to get the list of videos. eg
https://www.googleapis.com/youtube/v3/playlistItems?playlistId={"uploads" Id}&key={API key}&part=snippet&maxResults=50
Solution 4
To get channels list :
Get Channels list by forUserName:
Get channels list by channel id:
Get Channel sections:
To get Playlists :
Get Playlists by Channel ID:
Get Playlists by Channel ID with pageToken:
https://www.googleapis.com/youtube/v3/playlists?part=snippet,contentDetails&channelId=UCq-Fj5jknLsUf-MWSy4_brA&maxResults=50&key=&pageToken=CDIQAA
To get PlaylistItems :
Get PlaylistItems list by PlayListId:
To get videos :
Get videos list by video id:
Get videos list by multiple videos id:
Get comments list
Get Comment list by video ID:
https://www.googleapis.com/youtube/v3/commentThreads?part=snippet,replies&videoId=el****kQak&key=A**********k
Get Comment list by channel ID:
https://www.googleapis.com/youtube/v3/commentThreads?part=snippet,replies&channelId=U*****Q&key=AI********k
Get Comment list by allThreadsRelatedToChannelId:
https://www.googleapis.com/youtube/v3/commentThreads?part=snippet,replies&allThreadsRelatedToChannelId=UC*****ntcQ&key=AI*****k
Here all api's are Get approach.
Based on channel id we con't get all videos directly, that's the important point here.
For integration https://developers.google.com/youtube/v3/quickstart/ios?ver=swift
Solution 5
Here is the code that will return all video ids under your channel
<?php
$baseUrl = 'https://www.googleapis.com/youtube/v3/';
// https://developers.google.com/youtube/v3/getting-started
$apiKey = 'API_KEY';
// If you don't know the channel ID see below
$channelId = 'CHANNEL_ID';
$params = [
'id'=> $channelId,
'part'=> 'contentDetails',
'key'=> $apiKey
];
$url = $baseUrl . 'channels?' . http_build_query($params);
$json = json_decode(file_get_contents($url), true);
$playlist = $json['items'][0]['contentDetails']['relatedPlaylists']['uploads'];
$params = [
'part'=> 'snippet',
'playlistId' => $playlist,
'maxResults'=> '50',
'key'=> $apiKey
];
$url = $baseUrl . 'playlistItems?' . http_build_query($params);
$json = json_decode(file_get_contents($url), true);
$videos = [];
foreach($json['items'] as $video)
$videos[] = $video['snippet']['resourceId']['videoId'];
while(isset($json['nextPageToken'])){
$nextUrl = $url . '&pageToken=' . $json['nextPageToken'];
$json = json_decode(file_get_contents($nextUrl), true);
foreach($json['items'] as $video)
$videos[] = $video['snippet']['resourceId']['videoId'];
}
print_r($videos);
Note: You can get channel id at https://www.youtube.com/account_advanced after logged in.
Related videos on Youtube
Rajendra Dewani
Updated on April 25, 2022Comments
-
Rajendra Dewani about 2 years
We need a video list by channel name of YouTube (using the API).
We can get a channel list (only channel name) by using the below API:
https://gdata.youtube.com/feeds/api/channels?v=2&q=tendulkar
Below is a direct link of channels
https://www.youtube.com/channel/UCqAEtEr0A0Eo2IVcuWBfB9g
Or
WWW.YouTube.com/channel/HC-8jgBP-4rlI
Now, we need videos of channel >> UCqAEtEr0A0Eo2IVcuWBfB9g or HC-8jgBP-4rlI.
We tried
https://gdata.youtube.com/feeds/api/videos?v=2&uploader=partner&User=UC7Xayrf2k0NZiz3S04WuDNQ https://gdata.youtube.com/feeds/api/videos?v=2&uploader=partner&q=UC7Xayrf2k0NZiz3S04WuDNQ
But, it does not help.
We need all the videos posted on the channel. Videos uploaded to a channel can be from multiple users thus I don't think providing a user parameter would help...
-
filthy_wizard over 4 yearscan i get access to my own video files. to essentially download my own content when logged in via the API!!!
-
-
Rajendra Dewani over 10 yearsFor UCqAEtEr0A0Eo2IVcuWBfB9g it works, i think this is because its uploaded by a single user. How about HC-8jgBP-4rlI
-
akshay over 10 yearsIt is easy to say, but why don`t you put your answer with a good and working example???
-
Als about 10 yearsDidn't check my messages until today. You're right. Only for an user channel.
-
Fábio Perez over 9 yearsThis will only return the first
maxResults=20
(up to 50) videos, but not the entire channel catalogue. If you want more results, use the pageToken as described here. -
macabeus over 9 yearsWhere is the documentation for that API?
-
Romulus Urakagi Ts'ai over 9 yearsI don't find where the requested feature is written in document. Videos have only three filters and none of them relate to channel.
-
akshay over 9 yearsRomulus Urakagi Ts'ai: while requesting videos you are giving channelId, that is the filter for channel.
-
Bruce van der Kooij over 8 yearsThis API is no longer available: "The YouTube Data API (v2) has been officially deprecated as of March 4, 2014"
-
kristopolous about 8 yearsNot everyone has a youtube username in this brand new world. Some of them only have a google+ user id number, which doesn't work in the place of a youtube username
-
user3078414 almost 8 yearsThe link is dead.
-
Tony Paternite over 7 yearsWorth noting you can only get up to 500 videos from a channel using the next page tokens.
-
Goodlife over 7 yearsUsing the browser Key will save you tie in android too and create your own HTTP CLIENT LIKE Retrofit to fetch data
-
Raja over 7 years@TonyPaternite How do I get more than 500 videos. I am currently facing this issue.
-
Raja over 7 yearsThe issue is explained well here. code.google.com/p/gdata-issues/issues/detail?id=4282 Trying with a different range of dates is one way to get more videos it seems.
-
Tony Paternite over 7 years@Raja Yeah, I would try that option with the date range. The API doesn't allow more than 500 results from a channel.
-
Ignat over 7 years@kristopolous Every YouTube channel has a channel ID. If you go to a YouTube page via Google plus, it uses the Google plus user id as the link to the channel. If you went to the channel from a YouTube video, it uses YouTube's channel ID property instead.
-
JP de la Torre over 7 yearsThis is perfect. Particularly because it only spends 2 quota points instead of 100 (that the search call would spend).
-
Ken Sharp over 7 years@kristopolous is correct: you can't use those channel IDs as names.
-
hello_there_andy over 7 yearsMay I ask what
?key={your_key_here}
needs, specifically, what is:your_key_here
? How can I get that? -
akshay over 7 years@hello_there_andy : You need a Google Account to access the Google Developers Console, request an API key, and register your application. For more info, please check : developers.google.com/youtube/v3/getting-started
-
Muhammad about 7 yearsNotice that playlist items api will include unlisted and deleted videos too, but you can use search api to list public videos only by channel id
-
ishandutta2007 about 7 yearsCan "uploads" Id change for a given channel ?
-
ishandutta2007 about 7 yearssomteimes it(developers.google.com/youtube/v3/docs/playlistItems/list#try-it) works , sometimes it throws 404 for same uploadId, don't know whats going on.
-
ishandutta2007 about 7 yearsseems uploads are same as channelId , but terribly inconsistent APIs, can some answer this stackoverflow.com/questions/43568521/…
-
mwm over 6 yearsthis also includes the channel item. for me it works adding also type=video
-
Adrien H about 6 yearsYou can try the api here : developers.google.com/apis-explorer/#search/youtube/youtube/v3/… (apis-exporer - > youtube data api -> search.list ), don't forget to set the parameter type to "video".
-
Joffrey Baratheon almost 6 yearsHow does this work? I pasted the API KEY using single quotes ' ' into the api_key variable, then I called the function passing in the channel id, then ran the python program, but nothing happens.
-
Joffrey Baratheon almost 6 yearsAre you sure that this works? The GitHub page is gone and then when I input API Key and channel id into the fields, I get errors.
-
Nikhil VJ almost 6 years@JoffreyBaratheon thanks for pointing out the broken github link. I just ran it.. it works. Getting that playlist id is tricky.. pls see this: github.com/answerquest/answerquest.github.io/issues/2
-
vicke4 almost 6 years@ishandutta2007 no uploads id is different from channel id.
-
phapha pha almost 6 years@JoffreyBaratheon the function return an array, you need to contain that to a variable. For example :
video_list = get_all_video_in_channel("ABC123EFG456")
then you could print it to see the array usingprint(video_list)
-
cdlvcdlv almost 6 yearsI think this is the best answer since it doesn't need API key. To make it even more automated you can use
@for /f "usebackq tokens=2 delims=: " %a in (`dl-list.py^|findstr information`) do @echo https://www.youtube.com/watch?v=%a
. It will print all the URL of the videos.PLAYLIST_ID
can be a playlist or channel ID. -
cdlvcdlv almost 6 yearsYou can infer it but I forgot to say that I saved the code as
dl-list.py
. -
Harsh sachdev about 5 years@jambrose in the playlistItems endpoint how to use some date range parameter like publishAfter/ publishedBefore. I tried It, not working So how I fetch all the videos of a channel.
-
Jan Bludau almost 5 yearsnice job. works very well with the updated github link. you will need jquery and papaparse.min.js
-
Nikhil VJ almost 5 years@thE_iNviNciblE thanks for bringing that up. made a mention of it.
-
Jan Bludau almost 5 years@nikhil-vj it's not useable for a real world szenario, you shouldn't give the Client Browser the youtube API-Token. But for programming education quite nice job :-)
-
Nikhil VJ almost 5 years@thE_iNviNciblE that's why I let the user put in their own token :P . But API tokens are used all over the net; one can put url restrictions IP restrictions etc at the token management side so even if people take it they can't use it at their end. We can dispose tokens and make new ones quickly. It's not trivial, but not too critical of a threat either.
-
Madushan almost 5 yearsI was scraping channel pages because search endpoint costs 100 points. Liek to say a big THANK YOU for this one. This was not obvious from the docs and it works perfectly. Also the search call doesn't necessarily return only the specified channel, and it gives up after a few 100 results. This endpoint seem to work fine.
-
Khom Nazid almost 5 yearsDoes this get all the videos with titles, URL of the video, an image identifying the video, number of likes/comments? Some info on how this publishes would be helpful. Thanks.
-
Aaska Patel almost 5 years@virtualmic@Peter Perfect Solution Guys , Thanks
-
Mago Maverick almost 5 yearsThis one is definitely a clean solution that works. Currently using in production.
-
CMash over 4 yearsbeware of using search as it has a quote cost of 100!
-
Berry Blue over 4 years@CMash This is the issue that I'm encountering. You run through your quota very fast.
-
jtubre over 4 yearsIf you want to reduce quota by another 2 units, set part=snippet only. contentDetails (videoId, videoPublishedAt) can be found inside the snippet node so it's redundant.
-
Onkar Musale over 4 yearsit is working fine. but i have multiple channel ids, so how can i send them to api, can i use comma seperated channel ids
-
Onkar Musale over 4 yearsHow can i send multiple channel ids to api, can i use comma separated channel ids
-
Matt Booth about 4 years@vicke4 is correct, they are different and it looks like from the channels I deal with (quite a few) that the channels' uploads ID is the same as the Channel ID, except it starts with UU instead of UC. This may not be a certainty though, I can't find any doco about it.
-
Teemoh about 4 yearsPlease note: the
search
operation is very expensive (100 quota) compared to the operations suggested by jambrose (3 + 5 quota) (as of march 2020). See Quota Calculator. -
poke almost 4 yearsFor those that need it - I implemented this approach, you can try it online: yts.sourceforge.net/getchannelvideos.html
-
Rajeshwar almost 4 yearsHow can i get the top 10/50/100 youtube channels using api?
-
IvanM almost 4 yearsit may miss some videos! Instead, use "uploads" playlist as described below stackoverflow.com/a/27872244/2154075
-
Yasin Okumuş over 3 yearsEven though this might be the quickest way, the cost of "search" is 100 unit and that may result quota exceed.
-
Asylzat over 3 yearsthanks man, it really works just pasted and everything works great!
-
Scuilla over 3 years@MattBooth is spot on. It seems the pattern is Channel ID = UC + { User ID }, Upload Playlist ID = UU + { User ID } . I'm guessing it's auto-generated for every channel at the point of creation (or for old channels, when the switch happened from YT's API to Google's). Still can't find any source that confirms it, but through testing a few hundred channels, they were all followed this pattern. UC would make sense to denote User Channel, while UU could be User Uploads.
-
TrisT over 3 yearsYou can ofc use a channel ID to get this information in the first place, just specify the
id
parameter instead offorUsername
. If you're attempting to get the upload playlist for multiple channels at once like I am, you can specify multiple IDs with either a comma or using theid
parameter multiple times. -
TrisT over 3 yearsAlso, one thing I noticed is that as (as far as I can see), the uploads playlist ID is the same as the channel ID with the second character from the left replaced with a U. So for instance the uploads playlist for channelID
UC-lHJZR3Gqxm24_Vd_AJ5Yw
would beUU-lHJZR3Gqxm24_Vd_AJ5Yw
. Makes sense, I assume it would stand for "user channel" and "user uploads". So if you need a few extra quota points I suppose that could be a solution. -
ying over 3 yearsIs there a way to search video later than a timestamp?
-
jave.web over 3 yearsCan you please add the information about how to get ALL videos using this based on
pageToken
from the 2nd part,so the answer is complete for this Q. (I know how to do it, but just for others) :) -
John Funk about 3 yearsThis is exactly what I was looking for, using the "upload" playlist id is far from being intuitive.
-
Tassoman about 3 yearsJFYF live videos are missing from the uploads related playlist of the channel
-
teran about 3 yearsit looks like api limits to 20k videos in playlist while search with empty query returns 26k videos
-
teran about 3 yearslooks like this is limited up to 20k videos
-
Antony about 3 yearsIts also worth saying that if the forUsername stops working - revisit the page, and see if it defaults to an ID instead. One of my forUsernames wasn't working but grabbing the ID instead did.
-
Duncan Marshall about 3 yearsI tried this but it failed with a quota exceeded error, even the only thing I've done with my quota is tried this query and got that error - it's a brand new project. Anything about this that could have caused that?
-
Emiswelt over 2 yearsAnd how do you resolve the playlist_id from the channel list?
-
Ammar Alyousfi over 2 yearsThis does not return all channel's videos. It returns all videos in the uploads playlist, but not all channel's videos.
-
jfar_2020 over 2 years@jambrose How can this be modified to include view count too? I can list all videos from a specific playlist but I need view count too, if I simply change part=snippet to part=snippet,statistics I then get no results.
-
Tom about 2 yearsTo Download the List one can use Youtube API, too. There is no need to use additional tools like
youtube-dl