I am currently learning the use of the youtube api. I want to retrieve all playlists id from a channel id. I read through the documentation and saw that I can use youtube.channels.list for such task. I did basic testing on the api_page. Still, I am not able to figure what params to use to get the playlist id. How can I retrieve all playlist ids from a given channel id?
https://www.googleapis.com/youtube/v3/channels?part=id&id=UCF0pVplsI8R5kcAqgtoRqoA&key={YOUR_API_KEY}
A simple way :
With the YouTube API v3 with the ressource playlists.list
Use this parameters to get the playlists ID of a channel :
part: 'snippet'
channelId: 'UCBkNpeyvBO2TdPGVC_PsPUA'
https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId=UCBkNpeyvBO2TdPGVC_PsPUA&key={YOUR_API_KEY}
The output :
"items": [
{
"kind": "youtube#playlist",
"etag": "\"PSjn-HSKiX6orvNhGZvglLI2lvk/K21sgPQuMRCjhSMBjm3v3n5tl1o\"",
"id": "PL2qcutlDmS0CnyV8Jcbl2d7yFxd2iGg67",
"snippet": {
"publishedAt": "2014-07-08T03:13:37.000Z",
"channelId": "UCBkNpeyvBO2TdPGVC_PsPUA",
"title": "These Things Happen Series",
"description": "",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/93mgU_VXZrA/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/93mgU_VXZrA/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/93mgU_VXZrA/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/93mgU_VXZrA/sddefault.jpg",
"width": 640,
"height": 480
},
"maxres": {
"url": "https://i.ytimg.com/vi/93mgU_VXZrA/maxresdefault.jpg",
"width": 1280,
"height": 720
}
},
"channelTitle": "GEazyTV"
}
},
{
"kind": "youtube#playlist",
"etag": "\"PSjn-HSKiX6orvNhGZvglLI2lvk/5ifuvTYKbyV6DUPqbTa2bnO2jWY\"",
"id": "PL2qcutlDmS0B0jwHOQYzgRhJpnxDwPBHc",
"snippet": {
"publishedAt": "2014-06-05T07:36:58.000Z",
"channelId": "UCBkNpeyvBO2TdPGVC_PsPUA",
"title": "B-Sides",
"description": "",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/f7Ua9wKvVtI/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/f7Ua9wKvVtI/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/f7Ua9wKvVtI/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/f7Ua9wKvVtI/sddefault.jpg",
"width": 640,
"height": 480
},
"maxres": {
"url": "https://i.ytimg.com/vi/f7Ua9wKvVtI/maxresdefault.jpg",
"width": 1280,
"height": 720
}
},
"channelTitle": "GEazyTV"
}
},
...
This is a sample example with a random channel.
If you don't know how to get the channelID of a channel use ressource channels.list:
With this parameters to get the video ID of a playlist :
part: 'id'
forUsername: 'channel_name'
https://www.googleapis.com/youtube/v3/channels?part=id&forUsername=GEazyTV&key={YOUR_API_KEY}
"items": [
{
"kind": "youtube#channel",
"etag": "\"PSjn-HSKiX6orvNhGZvglLI2lvk/vIwM6ev74Om0AOupX26jJoEDELU\"",
"id": "UCBkNpeyvBO2TdPGVC_PsPUA"
}
I'm not sure how I came across this solution, but I've found that if you follow these steps then you can retrieve the playlistID to use:
Create an API Key using the Google API Console.
Use
https://www.googleapis.com/youtube/v3/channels?part=contentDetails&key=[KEY FROM GOOGLE API CONSOLE]&id=[CHANNEL ID]
where you are replacing everything, including the brackets, with the corresponding info (I find channel ids are easy to come by since they are normally in the URL. The PlaylistID is the one that tends to be difficult).
The resulting feed from the URL in step 2 should contain an uploads object, containing the playlistID which is used in the URL in step 4.
Use
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=[PLAYLIST ID RETRIEVED IN STEP 3 HERE]&key=[KEY FROM GOOGLE API CONSOLE]
The link from step 4 is what should end up being used in the app.
This works for me every time, and I integrate the YouTube v3 API in many apps. I completely agree with #Utkanos' comment that while #mpgn's answer works sometimes, it certainly doesn't work for all channels.
Youtube Api v3 Channel Playlist video max 50
This url format work
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=[]&key=[]&maxResults=50
Related
I am using the Playlists endpoint of Youtube's API to get the playlists from a specific channel but it doesn't work for the following channels:
https://www.youtube.com/channel/UCX5fyLRcU05DMa2OVu-qFEQ
https://www.youtube.com/channel/UCwm2mdiUXApmL5bCxHtgJIA
The query I am using:
https://www.googleapis.com/youtube/v3/playlists?channelId=UCwm2mdiUXApmL5bCxHtgJIA&part=snippet&order=date&maxResults=50&key=YOUR_API_KEY
https://www.googleapis.com/youtube/v3/playlists?channelId=UCX5fyLRcU05DMa2OVu-qFEQ&part=snippet&order=date&maxResults=50&key=YOUR_API_KEY
It doesn't return the videos when I try to target the playlists in these channels using the specif Playlist ID as well. I can see that these channels, playlists and videos are public and searchable.
Is there any reason why the API shouldn't return this playlist that I am missing?
Thank you for your help.
Bartu
If you check the playlist page of the channel you provided, you'll see that all playlists posted there are not really from the channel - those were added/generated by YouTube itself.
Example:
https://www.youtube.com/playlist?list=OLAK5uy_nvZSUlZB8qwifPgIVCoEulF4VyErdBX48
A normal playlist (that belongs to the channel) should have its ID as follows:
PL3tRBEVW0hiB5KKP9gs_AkW8J4dOvbdPN
By using YouTube Data API, you can test the results:
URL: https://youtube.googleapis.com/youtube/v3/playlists?part=id%2Csnippet%2Cstatus&id=OLAK5uy_nvZSUlZB8qwifPgIVCoEulF4VyErdBX48&key=[YOUR_API_KEY]
Results:
{
"kind": "youtube#channelListResponse",
"etag": "Yw1yJOOwI7LJ8LeYmvQ8wpyHWbU",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#channel",
"etag": "wDhMSGEntArTZuX56hjNjytDUlU",
"id": "UCFtEEv80fQVKkD4h1PF-Xqw",
"snippet": {
"title": "Microsoft",
"description": "Innovation is a key ingredient in Microsoft’s mission: to empower every person and organization on the planet to achieve more. \n\nSubscribe to Microsoft's official YouTube channel to explore technology’s role in making the world more sustainable, inclusive, and innovative for all.\n\n",
"customUrl": "microsoft",
"publishedAt": "2006-02-13T05:21:44Z",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/ytc/AKedOLRZENZBPyEEG2cd0PZXemKKyG1GMGVJXmzHhrs4=s88-c-k-c0x00ffffff-no-rj",
"width": 88,
"height": 88
},
"medium": {
"url": "https://yt3.ggpht.com/ytc/AKedOLRZENZBPyEEG2cd0PZXemKKyG1GMGVJXmzHhrs4=s240-c-k-c0x00ffffff-no-rj",
"width": 240,
"height": 240
},
"high": {
"url": "https://yt3.ggpht.com/ytc/AKedOLRZENZBPyEEG2cd0PZXemKKyG1GMGVJXmzHhrs4=s800-c-k-c0x00ffffff-no-rj",
"width": 800,
"height": 800
}
},
"localized": {
"title": "Microsoft",
"description": "Innovation is a key ingredient in Microsoft’s mission: to empower every person and organization on the planet to achieve more. \n\nSubscribe to Microsoft's official YouTube channel to explore technology’s role in making the world more sustainable, inclusive, and innovative for all.\n\n"
},
"country": "US"
},
"contentDetails": {
"relatedPlaylists": {
"likes": "",
"uploads": "UUFtEEv80fQVKkD4h1PF-Xqw"
}
},
"status": {
"privacyStatus": "public",
"isLinked": true,
"longUploadsStatus": "longUploadsUnspecified"
}
}
]
}
When you query a normal playlist (that belongs to the channel), you will get these results:
URL: https://youtube.googleapis.com/youtube/v3/playlists?part=id%2Csnippet%2Cstatus&id=PL3tRBEVW0hiB5KKP9gs_AkW8J4dOvbdPN&key=[YOUR_API_KEY]
Results:
{
"kind": "youtube#playlistListResponse",
"etag": "OV6gnfMDH09mU3YBdHPuf5uz1Jg",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#playlist",
"etag": "X8YVDKLXZZfHlVTh_ud0LD-IMMQ",
"id": "PL3tRBEVW0hiB5KKP9gs_AkW8J4dOvbdPN",
"snippet": {
"publishedAt": "2016-05-15T15:29:30Z",
"channelId": "UC7_YxT-KID8kRbqZo7MyscQ",
"title": "DOOM",
"description": "",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/pCygvprsgIk/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/pCygvprsgIk/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/pCygvprsgIk/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/pCygvprsgIk/sddefault.jpg",
"width": 640,
"height": 480
},
"maxres": {
"url": "https://i.ytimg.com/vi/pCygvprsgIk/maxresdefault.jpg",
"width": 1280,
"height": 720
}
},
"channelTitle": "Markiplier",
"localized": {
"title": "DOOM",
"description": ""
}
},
"status": {
"privacyStatus": "public"
}
}
]
}
Check this answer for more details.
Can successfully search API for list of videos within a certain radius of a latlong, but how do I access the latlong from the response data?
I've used both YouTube's API playground tool and Postman as well as run some sample code in VSCode. Here is what 1 entry in the response list of "items" looks like. Also, where's the URL to the video?
{
"kind": "youtube#searchResult",
"etag": "\"j6xRRd8dTPVVptg711_CSPADRfg/fsqRXEIJN16lp5xdhifY88TcbVg\"",
"id": {
"kind": "youtube#video",
"videoId": "5QPeyrHwlwk"
},
"snippet": {
"publishedAt": "2019-10-27T12:24:13.000Z",
"channelId": "UCT350j4u6alUKyF9eu2bGug",
"title": "Kincade Fire, PG&E Power Shutoffs, Extreme winds across California | Live overnight coverage",
"description": "Kincade Fire, PG&E Power Shutoffs, Extreme winds across California | Live overnight coverage 900000+ customers lose power due to PG&E public safety ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/5QPeyrHwlwk/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/5QPeyrHwlwk/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/5QPeyrHwlwk/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "ABC10",
"liveBroadcastContent": "none"
}
}
I would expect the response data to actually have the latitude and longitude, since I entered it into my query, but where is it? I've heard there's a property called 'recordingDetails' but how the heck do I get at it? I'm assuming this is just showing me the 'snippet' part, but is there another part I can query?
We are using youtube v3 search API. We are getting mismatch in the "totalResults" count and the list of items returned in the response.items field. I am requesting 50 videos in the request. Response returned shows totalResults count as 65 but the response payload has only 3 videos.
API : www.googleapis.com/youtube/v3/search/list
Request Payload
{key=API_KEY, maxResults=50, order=date, part=snippet, publishedAfter=2017-03-20T23:59:59.999-04:00, publishedBefore=2017-04-19T23:59:59.001-04:00, q=( ( "Wood Mackenzie" OR "Wood Mac" OR Woodmac OR #woodmackenzie ) AND NOT (fleetwood OR "fleet wood" OR 9WoodMac ) ) , type=video}
Response Payload
{
"kind": "youtube#searchListResponse",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/HTW4WQODZeERIv51VrRfOhir8dg\"",
"nextPageToken": "CDIQAA",
"regionCode": "US",
"pageInfo": {
"totalResults": 65,
"resultsPerPage": 50
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/lnNNrToZHGTehIEJ6bvEx5RZMo4\"",
"id": {
"kind": "youtube#video",
"videoId": "obzlB21t904"
},
"snippet": {
"publishedAt": "2017-04-14T11:38:08.000Z",
"channelId": "UC60Sa1LQjgy_a-K8ThN4eQw",
"title": "Fleet wood mac Live at Leeds",
"description": "",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/obzlB21t904/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/obzlB21t904/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/obzlB21t904/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "KEVIN MARSHALL",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/uYuuTAL3vtnFI1WOYjth0cso2Xo\"",
"id": {
"kind": "youtube#video",
"videoId": "gHAn0SbwKMg"
},
"snippet": {
"publishedAt": "2017-04-06T22:17:31.000Z",
"channelId": "UC3_MxBSSbmGznoSTgoBQ7_w",
"title": "Beat Club: British Invasion 60's, Pt-2; Animals-Move-Fleet Wood Mac-J.Mayall-Who-Pacemakers-Kinks",
"description": "Eric Burdon & Animals: C.C. Rider 0:01 The Move: Wild Tiger Woman 3:55 Fleet Wood Mac: Dragonfly 6:26 John Mayall: My Pretty Girl 9:47 Thunderclap ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/gHAn0SbwKMg/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/gHAn0SbwKMg/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/gHAn0SbwKMg/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "ROCK&POPS1_koba",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/tapelxOG4Q3gZRJCR2qaVdt-ZO8\"",
"id": {
"kind": "youtube#video",
"videoId": "5GvLbFBdcF4"
},
"snippet": {
"publishedAt": "2017-04-02T04:48:47.000Z",
"channelId": "UC6fn383TI1HVDYW4dSEIogQ",
"title": "\"Dreams\" by fleet wood mac (vocal cover)",
"description": "I do not own this song. I do not make a profit off of this song. It belongs to the person(s) who wrote it. Please subscribe and comment below any suggestions?!",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/5GvLbFBdcF4/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/5GvLbFBdcF4/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/5GvLbFBdcF4/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Musikallitee",
"liveBroadcastContent": "none"
}
}
]
}
As described in the documentation itself, the totalResults is:
integer
The total number of results in the result set.Please note that the value is an approximation and may not represent an exact value. In addition, the maximum value is 1,000,000.
You should not use this value to create pagination links. Instead, use the nextPageToken and prevPageToken property values to determine whether to show pagination links.
The value is only an approximation/estimate, but not the exact value for the total number of items returned. I've tested the API with the same details as yours and the value tends to change from 63, to 64, and 65.
With all that said, there is nothing wrong in your code. It's just the expected behavior. Unfortunately, it is not stated anywhere as to where the value of totalResults is based on or where it is best used. It's best to proceed with an implementation that doesn't rely on this parameter.
According to the docs at https://developers.google.com/youtube/v3/docs/videoCategories, a videoCategory having assignable set to false means that videos cannot "be associated with the category." However, in reality, I frequently see newly-posted videos in non-assignable categories. For instance, category 44, Trailers, is not assignable:
{
"kind": "youtube#videoCategoryListResponse",
"etag": "\"sZ5p5Mo8dPpfIzLYQBF8QIQJym0/eD61zd9m0XnQ2ZM5b9n0Q8fREKY\"",
"items": [
{
"kind": "youtube#videoCategory",
"etag": "\"sZ5p5Mo8dPpfIzLYQBF8QIQJym0/x5NxSf5fz8hn4loSN4rvhwzD_pY\"",
"id": "44",
"snippet": {
"channelId": "UCBR8-60-B28hp2BmDPdntcQ",
"title": "Trailers",
"assignable": false
}
}
]
}
But https://www.youtube.com/watch?v=fV4CL3ec-C0, published under half an hour ago, is in that category, as can be seen by querying the videos list API:
{
"kind": "youtube#videoListResponse",
"etag": "\"sZ5p5Mo8dPpfIzLYQBF8QIQJym0/NWLSF1NxIRL6hEGPkRpbFpl6ShA\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"sZ5p5Mo8dPpfIzLYQBF8QIQJym0/TMALCjmdQYcndOpePwtvPYbaBBI\"",
"id": "fV4CL3ec-C0",
"snippet": {
"publishedAt": "2016-11-07T11:00:03.000Z",
"channelId": "UCxk91kWNnZEIyE-1HgqzvHw",
"title": "USS Indianapolis: The Legacy - Trailer",
"description": "Based on the largest collection of original source material available on the subject, The Legacy Project is a complete re-telling of the story of the USS Indianapolis, told first hand, by those who lived through the experience.",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/fV4CL3ec-C0/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/fV4CL3ec-C0/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/fV4CL3ec-C0/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/fV4CL3ec-C0/sddefault.jpg",
"width": 640,
"height": 480
},
"maxres": {
"url": "https://i.ytimg.com/vi/fV4CL3ec-C0/maxresdefault.jpg",
"width": 1280,
"height": 720
}
},
"channelTitle": "GravitasVODGlobal",
"tags": [
"Military",
"WWII",
"Indianapolis",
"McVay",
"Navy",
"Atomic Bomb",
"Sharks",
"Cruiser",
"Hunter Scott",
"Pacific War"
],
"categoryId": "44",
"liveBroadcastContent": "none",
"localized": {
"title": "USS Indianapolis: The Legacy - Trailer",
"description": "Based on the largest collection of original source material available on the subject, The Legacy Project is a complete re-telling of the story of the USS Indianapolis, told first hand, by those who lived through the experience."
}
}
}
]
}
By what mechanism do new videos get added to non-assignable categories? Are there some secret APIs available only to certain clients that YouTube has special deals with, or is there a publicly-documented mechanism for adding videos to non-assignable categories? Either way, is there any way for developers to distinguish these categories that are only nominally non-assignable from those that will truly not accept new videos via any means?
I'm using this url:
https://www.googleapis.com/youtube/v3/playlistItems?
playlistId=FLFe0SGNFqZ9E2owO5ZDZpeg&
part=snippet,contentDetails,status
to fetch YouTube playlistItems.
I included all the part I'm interested in, however I found no way to return the duration of the item.
https://developers.google.com/youtube/v3/docs/playlistItems/list
Is this possible?
currently I'm getting back only an item like this:
{
"status": {
"privacyStatus": "public"
},
"kind": "youtube#playlistItem",
"contentDetails": {
"videoId": "tL-Ba86UhoE"
},
"snippet": {
"playlistId": "FLFe0SGeFqZ9E2owO5ZDZpwg",
"thumbnails": {
"default": {
"url": "https://i1.ytimg.com/vi/tL-BA86Uhoh/default.jpg",
"width": 120,
"height": 90
},
"high": {
"url": "https://i1.ytimg.com/vi/tL-BA86Uhoh/hqdefault.jpg",
"width": 480,
"height": 360
},
"medium": {
"url": "https://i1.ytimg.com/vi/tL-BA86Uhoh/mqdefault.jpg",
"width": 320,
"height": 180
}
},
"title": "Music Video",
"resourceId": {
"kind": "youtube#video",
"videoId": "tL-BA86Uhoh"
},
"channelId": "UCFe0SGNFqZ9E2owO5ZDZpwg",
"publishedAt": "2013-07-06T18:41:43.000Z",
"channelTitle": "channeltitle",
"position": 0,
"description": "Video for"
},
"etag": "\"ePFRUfYBkeQ2ncpP9OLHvB0fDw4/CJiCG6tvFw4quQlzJq3gTrhvCNo\"",
"id": "FL-fX6VqgtTfCJWKNE4aVRODKSrRgEdGvw"
},
With no time indication at all.
I'd rather avoid flooding YouTube with request to return a single video's duration.
Use link like this for get duration for many videos:
https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=idFirst,idSecond&key=YOUR_API_KEY
Use this Function : [ only used with Youtube Api v3 ]
Browser :
you have to make another http request
using :
https://www.googleapis.com/youtube/v3/videos?id={video id}&part=contentDetails&key={api Key}
and on
contentDetails
you will find the duration
Php :
function getDuration($apiKey,$video_id){
$link='https://www.googleapis.com/youtube/v3/videos?id='.$video_id.'&part=contentDetails&key='.$apiKey;
$data = json_decode(file_get_contents($link),true);
$duration = $data['items'][0]['contentDetails']['duration'];
return $duration;
}