Related
I specified a certain channelId in the YouTube Data API query, but the results include videos from outside that channel:
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCVZyJ-yJ60EZyMXLnIs0_OA&maxResults=5&key={{your key}}
In the results there are items that are not from the channel specified by the parameter channelId in the request:
{
"kind": "youtube#searchListResponse",
"etag": "CqAEn3U3yOet5Dzo4akpnniRK58",
"nextPageToken": "CAUQAA",
"regionCode": "JP",
"pageInfo": {
"totalResults": 8,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "PzY2_uuWT5JXecEOIgv5a4H3RsE",
"id": {
"kind": "youtube#video",
"videoId": "820RgL1fc8g"
},
"snippet": {
"publishedAt": "2019-08-16T10:25:55Z",
"channelId": "UC9FTt8SigjBd2bzzH3QCCVQ",
"title": "薬師寺 新管主への継承法要",
"description": "2019/8/16.",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/820RgL1fc8g/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/820RgL1fc8g/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/820RgL1fc8g/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "奈良テレビチャンネル",
"liveBroadcastContent": "none",
"publishTime": "2019-08-16T10:25:55Z"
}
},
{
"kind": "youtube#searchResult",
"etag": "JIDp4JJTHmn1YL3QpbfG7ZkIhWg",
"id": {
"kind": "youtube#video",
"videoId": "qwmHF5kvfuk"
},
"snippet": {
"publishedAt": "2016-07-04T04:19:41Z",
"channelId": "UCHeX3CiVyozXzcYjLqmkXuQ",
"title": "落合西光寺双盤念仏~5分ver",
"description": "製作…平成27年度埼玉県民俗文化財を活かした地域活性化実行委員会30分verはこちら…https://youtu.be/QcJjlwqNRqk.",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/qwmHF5kvfuk/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/qwmHF5kvfuk/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/qwmHF5kvfuk/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Hanno City",
"liveBroadcastContent": "none",
"publishTime": "2016-07-04T04:19:41Z"
}
},
{
"kind": "youtube#searchResult",
"etag": "WhRD0hdEdos_8_3sIMnSfKeBOos",
"id": {
"kind": "youtube#channel",
"channelId": "UCVZyJ-yJ60EZyMXLnIs0_OA"
},
"snippet": {
"publishedAt": "2019-03-15T07:18:32Z",
"channelId": "UCVZyJ-yJ60EZyMXLnIs0_OA",
"title": "世田谷デジタルミュージアム",
"description": "",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/ytc/AAUvwninEQgZmbCwRKlSlpaqXerK3i2pXTX2fw0ctyW5=s88-c-k-c0xffffffff-no-rj-mo"
},
"medium": {
"url": "https://yt3.ggpht.com/ytc/AAUvwninEQgZmbCwRKlSlpaqXerK3i2pXTX2fw0ctyW5=s240-c-k-c0xffffffff-no-rj-mo"
},
"high": {
"url": "https://yt3.ggpht.com/ytc/AAUvwninEQgZmbCwRKlSlpaqXerK3i2pXTX2fw0ctyW5=s800-c-k-c0xffffffff-no-rj-mo"
}
},
"channelTitle": "世田谷デジタルミュージアム",
"liveBroadcastContent": "none",
"publishTime": "2019-03-15T07:18:32Z"
}
},
{
"kind": "youtube#searchResult",
"etag": "mGoPgXXCpvtW28-eAzPkxjQ-goc",
"id": {
"kind": "youtube#video",
"videoId": "DgeWR7q2_V4"
},
"snippet": {
"publishedAt": "2014-08-22T05:32:22Z",
"channelId": "UC_kYlv-j7o3j1979t35htzQ",
"title": "双盤念仏(そうばんねんぶつ) 九品仏浄真寺 閻魔堂 平成26年",
"description": "東京都世田谷区にある九品仏浄真寺の閻魔堂で行われた双盤念仏(そうばんねんぶつ)です。 平成26年8月16日(土)撮影.",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/DgeWR7q2_V4/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/DgeWR7q2_V4/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/DgeWR7q2_V4/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "ヒコボン/ohiko2000",
"liveBroadcastContent": "none",
"publishTime": "2014-08-22T05:32:22Z"
}
},
{
"kind": "youtube#searchResult",
"etag": "f6Uukvz6P_iy8eqLdGrIckIzV6w",
"id": {
"kind": "youtube#video",
"videoId": "RPtB3ibF9Mg"
},
"snippet": {
"publishedAt": "2015-10-15T08:42:50Z",
"channelId": "UCH2rOy40BxSSfNZwcCuVGzg",
"title": "平成27年10月13日建長寺僧堂落慶法要",
"description": "",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/RPtB3ibF9Mg/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/RPtB3ibF9Mg/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/RPtB3ibF9Mg/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "建長寺",
"liveBroadcastContent": "none",
"publishTime": "2015-10-15T08:42:50Z"
}
}
]
}
This very basic query is responding with wrong results:
https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=10&publishedAfter=2019-01-01T00:00:00Z&key={MY_KEY}
The result set includes items before 2019-01-01T00:00:00Z for the publishedAt field. My application is broken entirely because it relies on this filter. I'm facing the problem after 16 March 2019. Here is the query result:
{
"kind": "youtube#searchListResponse",
"etag": "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/WppcKwINdbdkHMpSM_vz32bjgA4\"",
"nextPageToken": "CAoQAA",
"regionCode": "DE",
"pageInfo": {
"totalResults": 1000000,
"resultsPerPage": 10
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/0LG4Jg0EV14c5UiMLdaaet_v2CM\"",
"id": {
"kind": "youtube#video",
"videoId": "UOxkGD8qRB4"
},
"snippet": {
"publishedAt": "2018-11-03T07:30:00.000Z",
"channelId": "UC2t5bjwHdUX4vM2g8TRDq5g",
"title": "K/DA - POP/STARS (ft Madison Beer, (G)I-DLE, Jaira Burns) | Official Music Video - League of Legends",
"description": "K/DA Ahri, K/DA Evelynn, K/DA Kai'Sa, and K/DA Akali take the world stage with their debut single. Keep the show going on the Rift with these new Epic skins.",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/UOxkGD8qRB4/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/UOxkGD8qRB4/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/UOxkGD8qRB4/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "League of Legends",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/pqPk68pyu4UN0ALIfeVVFhIvYQo\"",
"id": {
"kind": "youtube#video",
"videoId": "m7Bc3pLyij0"
},
"snippet": {
"publishedAt": "2018-09-24T13:58:16.000Z",
"channelId": "UCEdvpU2pFRCVqU6yIPyTpMQ",
"title": "Marshmello ft. Bastille - Happier (Official Music Video)",
"description": "Marshmello ft. Bastille - Happier (Official Music Video) Download / Stream Happier ▷ http://marshmello.lnk.to/happier NEW Mello™ by Marshmello gear SHOP ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/m7Bc3pLyij0/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/m7Bc3pLyij0/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/m7Bc3pLyij0/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Marshmello",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/JHrxdxyihn5FHm1sbVQJxmw3cJY\"",
"id": {
"kind": "youtube#video",
"videoId": "56WBK4ZK_cw"
},
"snippet": {
"publishedAt": "2018-07-12T18:56:15.000Z",
"channelId": "UCqrBKQHQVEvD2Q9FP0DCP2g",
"title": "benny blanco, Halsey & Khalid – Eastside (official video)",
"description": "\"Eastside\" out now: http://smarturl.it/EastsideBB Directed by Jake Schreier Executive Producers: Jackie Kelman Bisbee, Alex Fisch Line Producer: Molly Gale ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/56WBK4ZK_cw/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/56WBK4ZK_cw/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/56WBK4ZK_cw/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "benny blanco",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/Cic0wO6Ki7l3BEeb2kx0VZtOQeA\"",
"id": {
"kind": "youtube#video",
"videoId": "hHW1oY26kxQ"
},
"snippet": {
"publishedAt": "2018-08-22T19:51:06.000Z",
"channelId": "UCSJ4gkVC6NrvII8umztf0Ow",
"title": "lofi hip hop radio - beats to relax/study to",
"description": "Thank you for listening, I hope you will have a good time here :) New merch available! → Listen to the sleepy lofi hip hop radio ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/hHW1oY26kxQ/default_live.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/hHW1oY26kxQ/mqdefault_live.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/hHW1oY26kxQ/hqdefault_live.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "ChilledCow",
"liveBroadcastContent": "live"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/l7d6Ky2ZMBiEckdYawqigvqGv4w\"",
"id": {
"kind": "youtube#video",
"videoId": "TcMBFSGVi1c"
},
"snippet": {
"publishedAt": "2019-03-14T12:05:18.000Z",
"channelId": "UCvC4D8onUfXzvjTOM-dBfEA",
"title": "Marvel Studios' Avengers: Endgame - Official Trailer",
"description": "Whatever it takes. Watch the brand-new trailer for Marvel Studios' Avengers: Endgame. In theaters April 26. ▻ Learn more: ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/TcMBFSGVi1c/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/TcMBFSGVi1c/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/TcMBFSGVi1c/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Marvel Entertainment",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/id3uz64VI_Frb6lxlzAYDG8yCuw\"",
"id": {
"kind": "youtube#video",
"videoId": "A2FsgKoGD04"
},
"snippet": {
"publishedAt": "2017-05-25T21:58:58.000Z",
"channelId": "UCRijo3ddMTht_IHyNSNXpNQ",
"title": "Real Life Trick Shots | Dude Perfect",
"description": "Trick shots should be an everyday thing! Thanks to Kingsford for sponsoring this video! ▻ Click HERE to subscribe to Dude Perfect! ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/A2FsgKoGD04/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/A2FsgKoGD04/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/A2FsgKoGD04/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Dude Perfect",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/1szGxIC2JpHOZayLDDyWY1wRMRg\"",
"id": {
"kind": "youtube#video",
"videoId": "VRJmcxCrAOA"
},
"snippet": {
"publishedAt": "2018-01-22T22:55:24.000Z",
"channelId": "UCRijo3ddMTht_IHyNSNXpNQ",
"title": "Real Life Trick Shots 2 | Dude Perfect",
"description": "Trick shots should be an everyday thing! Thanks to Kay Jewelers for sponsoring this video! Win Valentine's Day by going to http://dudeperfect.com/KayJewelers ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/VRJmcxCrAOA/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/VRJmcxCrAOA/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/VRJmcxCrAOA/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Dude Perfect",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/KijOZnDfYz96dVXIA2q3FHlMi_E\"",
"id": {
"kind": "youtube#video",
"videoId": "WXBHCQYxwr0"
},
"snippet": {
"publishedAt": "2018-08-27T16:26:25.000Z",
"channelId": "UCOwgc8DswjoBMuuUU2ScPvQ",
"title": "Ava Max - Sweet but Psycho [Official Music Video]",
"description": "\"Sweet but Psycho\" Available Now Download/Stream: https://avamax.lnk.to/SweetButPsychoID Subscribe for more official content from Ava Max: ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/WXBHCQYxwr0/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/WXBHCQYxwr0/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/WXBHCQYxwr0/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Ava Max",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/0O05twjfC6noThM59R5cemOe1pE\"",
"id": {
"kind": "youtube#video",
"videoId": "hA6hldpSTF8"
},
"snippet": {
"publishedAt": "2018-12-07T13:01:21.000Z",
"channelId": "UCvC4D8onUfXzvjTOM-dBfEA",
"title": "Marvel Studios' Avengers - Official Trailer",
"description": "Part of the journey is the end. ▻ Subscribe to Marvel: --- Follow Marvel on Twitter: ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/hA6hldpSTF8/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/hA6hldpSTF8/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/hA6hldpSTF8/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Marvel Entertainment",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/_60iD_MRSuskBGiBD0PfKUvmK64\"",
"id": {
"kind": "youtube#video",
"videoId": "rlR4PJn8b8I"
},
"snippet": {
"publishedAt": "2019-03-05T16:00:06.000Z",
"channelId": "UCQzdMyuz0Lf4zo4uGcEujFw",
"title": "Game of Thrones | Season 8 | Official Trailer (HBO)",
"description": "The trailer is here. #GameofThrones The Final Season begins April 14 on HBO.",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/rlR4PJn8b8I/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/rlR4PJn8b8I/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/rlR4PJn8b8I/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "GameofThrones",
"liveBroadcastContent": "none"
}
}
]
}
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.
I am using the YouTube API V3 for getting videos of a channel, but it returns the wrong number of videos. The channel has in total 11 videos, but when I do the call to the API, I get only 6 (or 7, I don't know the case) of them, also if I specify the maxResults parameter to 11 or higher.
How can I resolve this? Thanks. I didn't found any setting for this in my youtube account.
To demostrate it, the channel ID is: UCOjT220XvzZrX6LuZ6GnrGQ
When I call
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCOjT220XvzZrX6LuZ6GnrGQ&maxResults=13&order=date&key=[API_KEY]
I'm able to get the 11 videos you mentioned:
{
"kind": "youtube#searchListResponse",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/HAvUl5A7ZOXUisEPHf47emX1hL0\"",
"pageInfo": {
"totalResults": 12,
"resultsPerPage": 13
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/PgKUDIanQqJM06eGCdOcY1k8U2E\"",
"id": {
"kind": "youtube#video",
"videoId": "wgIGFp6LTpg"
},
"snippet": {
"publishedAt": "2015-02-27T09:00:41.000Z",
"channelId": "UCOjT220XvzZrX6LuZ6GnrGQ",
"title": "Trapianto di Cornea DALK",
"description": "",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/wgIGFp6LTpg/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/wgIGFp6LTpg/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/wgIGFp6LTpg/hqdefault.jpg"
}
},
"channelTitle": "",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/iI_e3liC80z1dubSCRt-GMMglqU\"",
"id": {
"kind": "youtube#video",
"videoId": "M48hn7bBof8"
},
"snippet": {
"publishedAt": "2015-02-27T08:57:31.000Z",
"channelId": "UCOjT220XvzZrX6LuZ6GnrGQ",
"title": "Cheratoprotesi di Boston",
"description": "La cornea artificiale è l'ultima frontiera per la cura delle malattie della cornea. Ne esistono di diversi tipi: la piu utilizzata è la Cornea artificiale (cheratoprotesi) di ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/M48hn7bBof8/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/M48hn7bBof8/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/M48hn7bBof8/hqdefault.jpg"
}
},
"channelTitle": "",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/0UZloLuYjiuCboAS78hx0Crez3E\"",
"id": {
"kind": "youtube#video",
"videoId": "Y2I2ZLpKDc8"
},
"snippet": {
"publishedAt": "2015-02-26T14:50:09.000Z",
"channelId": "UCOjT220XvzZrX6LuZ6GnrGQ",
"title": "Intralase",
"description": "Tecnologia laser a femtosecondi di Abbott Laboratories sulla quale si basa l'intervento LASIK.",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/Y2I2ZLpKDc8/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/Y2I2ZLpKDc8/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/Y2I2ZLpKDc8/hqdefault.jpg"
}
},
"channelTitle": "",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/d8MMhw3T03DfFfUHMUUkSWuOPyI\"",
"id": {
"kind": "youtube#video",
"videoId": "SbhcbwTLX7c"
},
"snippet": {
"publishedAt": "2015-02-26T14:26:30.000Z",
"channelId": "UCOjT220XvzZrX6LuZ6GnrGQ",
"title": "Trapianto di Cornea Endotelio DSAEK",
"description": "Trapianto di endotelio della cornea (DSAEK) con iniettore NCI. Nuova tecnica di trapianto di cornea per pazienti con distrofia di Fuchs o edema della cornea ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/SbhcbwTLX7c/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/SbhcbwTLX7c/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/SbhcbwTLX7c/hqdefault.jpg"
}
},
"channelTitle": "",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/Mb5mqYX17_L_9Y5t9FwSUcUhXI0\"",
"id": {
"kind": "youtube#video",
"videoId": "hKgget6QLMM"
},
"snippet": {
"publishedAt": "2015-02-25T14:18:26.000Z",
"channelId": "UCOjT220XvzZrX6LuZ6GnrGQ",
"title": "Cheratoprotesi di Boston: Trapianto di Cornea",
"description": "",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/hKgget6QLMM/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/hKgget6QLMM/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/hKgget6QLMM/hqdefault.jpg"
}
},
"channelTitle": "",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/qWC6lNxyC2DanUqXZjh9hnCE6a0\"",
"id": {
"kind": "youtube#video",
"videoId": "Zxe6N9gLYOk"
},
"snippet": {
"publishedAt": "2015-02-25T14:13:30.000Z",
"channelId": "UCOjT220XvzZrX6LuZ6GnrGQ",
"title": "Chirurgia Cataratta con lente Hi Tech",
"description": "",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/Zxe6N9gLYOk/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/Zxe6N9gLYOk/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/Zxe6N9gLYOk/hqdefault.jpg"
}
},
"channelTitle": "",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/4fEXZSXNyt6Er2llnk-Tq1-H3Xo\"",
"id": {
"kind": "youtube#video",
"videoId": "d-txNN-7LvE"
},
"snippet": {
"publishedAt": "2015-02-25T14:08:48.000Z",
"channelId": "UCOjT220XvzZrX6LuZ6GnrGQ",
"title": "Chirurgia Cheratocono con INTACTS - Chirurgia Live",
"description": "",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/d-txNN-7LvE/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/d-txNN-7LvE/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/d-txNN-7LvE/hqdefault.jpg"
}
},
"channelTitle": "",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/EeTGCvw9RrGuPB3KDSzZR0iGMEA\"",
"id": {
"kind": "youtube#video",
"videoId": "Imtlb7qmags"
},
"snippet": {
"publishedAt": "2015-02-25T14:05:24.000Z",
"channelId": "UCOjT220XvzZrX6LuZ6GnrGQ",
"title": "Chirurgia Cheratocono con INTACTS - Animazione",
"description": "",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/Imtlb7qmags/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/Imtlb7qmags/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/Imtlb7qmags/hqdefault.jpg"
}
},
"channelTitle": "",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/ssmNJT0LbRQRRlTGjJ-wbCNh5SM\"",
"id": {
"kind": "youtube#video",
"videoId": "ryWlPp29kiI"
},
"snippet": {
"publishedAt": "2015-02-25T13:57:46.000Z",
"channelId": "UCOjT220XvzZrX6LuZ6GnrGQ",
"title": "Correzione Miopia, Ipermetropia e Cataratta con la lente Hi Tech",
"description": "Correggere miopia, astigmatismo, presbiopia ed ipermetropia è possibile in un unico intervento grazie alla lente Hi-tech. Si tratta di un cristallino artificiale che ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/ryWlPp29kiI/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/ryWlPp29kiI/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/ryWlPp29kiI/hqdefault.jpg"
}
},
"channelTitle": "",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/YHFCRZaoPNuTzlLHmOAWzyydvZw\"",
"id": {
"kind": "youtube#video",
"videoId": "RJmm40oaVwk"
},
"snippet": {
"publishedAt": "2015-02-25T13:52:07.000Z",
"channelId": "UCOjT220XvzZrX6LuZ6GnrGQ",
"title": "Chirurgia della Cataratta: novità",
"description": "La più grande innovazione in chirurgia della cataratta è la lente Hi-Tech che permette di curare in un unico intervento miopia, astigmatismo, presbiopia e ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/RJmm40oaVwk/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/RJmm40oaVwk/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/RJmm40oaVwk/hqdefault.jpg"
}
},
"channelTitle": "",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/rs7lh7958amlLisrvdxndE1neAc\"",
"id": {
"kind": "youtube#video",
"videoId": "4sfAlyiSA8s"
},
"snippet": {
"publishedAt": "2015-02-25T08:35:34.000Z",
"channelId": "UCOjT220XvzZrX6LuZ6GnrGQ",
"title": "Lente Intraoculare Hi Tech",
"description": "I difetti della vista: miopia, astigmatismo, presbiopia e ipermetropia si possono finalmente correggere con un unico intervento: la chirurgia con la lente Hi-Tech o ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/4sfAlyiSA8s/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/4sfAlyiSA8s/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/4sfAlyiSA8s/hqdefault.jpg"
}
},
"channelTitle": "",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/NAW_LlewyAxUlC7o6lL1oQxW2VY\"",
"id": {
"kind": "youtube#channel",
"channelId": "UCOjT220XvzZrX6LuZ6GnrGQ"
},
"snippet": {
"publishedAt": "2015-02-24T18:10:32.000Z",
"channelId": "UCOjT220XvzZrX6LuZ6GnrGQ",
"title": "Micro Chirurgia Oculare - dott. Federico Badalà",
"description": "Il Dott. Federico Badalà dopo aver a lungo lavorato in USA è stato il primo chirurgo oculista italiano ad eseguire interventi innovativi nel campo della chirurgia ...",
"thumbnails": {
"default": {
"url": "https://lh5.googleusercontent.com/-lvWU6W_lntU/AAAAAAAAAAI/AAAAAAAAAAA/yKCZSRHZcNI/photo.jpg"
},
"medium": {
"url": "https://lh5.googleusercontent.com/-lvWU6W_lntU/AAAAAAAAAAI/AAAAAAAAAAA/yKCZSRHZcNI/photo.jpg"
},
"high": {
"url": "https://lh5.googleusercontent.com/-lvWU6W_lntU/AAAAAAAAAAI/AAAAAAAAAAA/yKCZSRHZcNI/photo.jpg"
}
},
"channelTitle": "",
"liveBroadcastContent": "none"
}
}
]
}
For some strange reason, it doesn't work when I copy the URL you posted in the comments, but when I copy the channelId posted above and paste that in your URL, it works (even though it's the same ID, how strange...). Another way you could try to do this is to use playlistItems.list and provide your uploads playlist ID (which you can get by calling channels.list and specifying part=contentDetails), which gives your uploaded videos in reverse chronological order.
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=UUOjT220XvzZrX6LuZ6GnrGQ&maxResults=13&key=[API_KEY]
I've been using the following method to retrieve all video IDs, titles, and default thumbnail images contained within a specific YouTube playlist for use in a dynamic playlist carousel (The IDs are then passed to an array which is used to dynamically create a thumbnail carousel. Note the 'playlist' variable is defined via an externalized XML value):
// Get YouTube Playlist values
var playListURL = 'http://gdata.youtube.com/feeds/api/playlists/' + playlist + '?v=2&alt=json&callback=?';
var videoURL = 'http://www.youtube.com/watch?v=';
$.getJSON(playListURL, function(data) {
var list_data = "";
$.each(data.feed.entry, function(i, item) {
var feedTitle = item.title.$t;
var feedURL = item.link[1].href;
var fragments = feedURL.split("/");
var videoID = fragments[fragments.length - 2];
var thumb = ""+ videoID +"/sddefault.jpg";
if (videoID !='videos') {
yt_videos.push(videoID);
}
yt_thumb.push(thumb);
yt_title.push(feedTitle);
});
$(list_data).appendTo(".cont");
populateCarousel();
});
YouTube has depricated the v1-2 APIs and the method is longer working. Does the YouTube API v3 provide an equivalent method? Specifically replacing the call:
var playListURL = 'http://gdata.youtube.com/feeds/api/playlists/' + playlist + '?v=2&alt=json&callback=?';
You will need to switch to the new PlaylistItems/list endpoint to get video information from a playlist.
Request:
HTTP GET: GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2C+id&playlistId=PLCJLiJ8uSJrCpxwz4lmnz1NvvF2SzXbhk&key={YOUR_API_KEY}
Response (for id= PLCJLiJ8uSJrCpxwz4lmnz1NvvF2SzXbhk):
{
"kind": "youtube#playlistItemListResponse",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/pBQT3k1NWD9D6HOvzNhT4QS1-W0\"",
"nextPageToken": "CAUQAA",
"pageInfo": {
"totalResults": 10,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#playlistItem",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/wu_RMwA6QYinWSMrYXyOugKDbyI\"",
"id": "PLl3eZeHB033DOxfNMOVENodvC_4QtQ-r2bxEjeNprDxQ",
"snippet": {
"publishedAt": "2014-12-10T21:16:39.000Z",
"channelId": "UCVUx0VcNxnHx7ZjuZK5Sthw",
"title": "Private video",
"description": "This video is private.",
"channelTitle": "Late Show with David Letterman",
"playlistId": "PLCJLiJ8uSJrCpxwz4lmnz1NvvF2SzXbhk",
"position": 0,
"resourceId": {
"kind": "youtube#video",
"videoId": "4bVgilYncao"
}
}
},
{
"kind": "youtube#playlistItem",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/DPNyicQckvtlwgMTintYEwYsE6g\"",
"id": "PLl3eZeHB033DOxfNMOVENoaZ-Ybk0W0zkTL1Sliq5xeA",
"snippet": {
"publishedAt": "2014-12-10T21:16:58.000Z",
"channelId": "UCVUx0VcNxnHx7ZjuZK5Sthw",
"title": "David Letterman Announces His Retirement from the Late Show",
"description": "David Letterman announces that he will retire from the Late Show in 2015.\n\nLive on Letterman is up for a Webby award! Let your voice be heard and vote now! http://bit.ly/1l4oktE #WebbyAwards",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/H9eYkpgeeI8/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/H9eYkpgeeI8/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/H9eYkpgeeI8/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/H9eYkpgeeI8/sddefault.jpg",
"width": 640,
"height": 480
},
"maxres": {
"url": "https://i.ytimg.com/vi/H9eYkpgeeI8/maxresdefault.jpg",
"width": 1280,
"height": 720
}
},
"channelTitle": "Late Show with David Letterman",
"playlistId": "PLCJLiJ8uSJrCpxwz4lmnz1NvvF2SzXbhk",
"position": 1,
"resourceId": {
"kind": "youtube#video",
"videoId": "H9eYkpgeeI8"
}
}
},
{
"kind": "youtube#playlistItem",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/aL6XWPV0PoM50wQcyclAxsvtWy4\"",
"id": "PLl3eZeHB033DOxfNMOVENobu4IxNcwxZw1eEEoLqHjhY",
"snippet": {
"publishedAt": "2014-12-10T21:17:14.000Z",
"channelId": "UCVUx0VcNxnHx7ZjuZK5Sthw",
"title": "Private video",
"description": "This video is private.",
"channelTitle": "Late Show with David Letterman",
"playlistId": "PLCJLiJ8uSJrCpxwz4lmnz1NvvF2SzXbhk",
"position": 2,
"resourceId": {
"kind": "youtube#video",
"videoId": "ONgN2Hgz3XE"
}
}
},
{
"kind": "youtube#playlistItem",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/YF1JYH8bTG20vjuPLeMR-2xkxjo\"",
"id": "PLl3eZeHB033DOxfNMOVENoQncF7sXo86YALoy5U4yqlU",
"snippet": {
"publishedAt": "2014-12-10T21:17:30.000Z",
"channelId": "UCVUx0VcNxnHx7ZjuZK5Sthw",
"title": "David Letterman - Future Islands: \"Seasons (Waiting On You)\"",
"description": "Making their network TV debut, Future Islands performed \"Seasons (Waiting On You)\" from their album, \"Singles.\"",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/1Ee4bfu_t3c/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/1Ee4bfu_t3c/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/1Ee4bfu_t3c/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Late Show with David Letterman",
"playlistId": "PLCJLiJ8uSJrCpxwz4lmnz1NvvF2SzXbhk",
"position": 3,
"resourceId": {
"kind": "youtube#video",
"videoId": "1Ee4bfu_t3c"
}
}
},
{
"kind": "youtube#playlistItem",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/_Ft_7ujRwQbP7-altelmVnzwQx0\"",
"id": "PLl3eZeHB033DOxfNMOVENoYQ9Z55P4r2KhvkV5yx-okc",
"snippet": {
"publishedAt": "2014-12-10T21:17:47.000Z",
"channelId": "UCVUx0VcNxnHx7ZjuZK5Sthw",
"title": "Private video",
"description": "This video is private.",
"channelTitle": "Late Show with David Letterman",
"playlistId": "PLCJLiJ8uSJrCpxwz4lmnz1NvvF2SzXbhk",
"position": 4,
"resourceId": {
"kind": "youtube#video",
"videoId": "Bzr5VtFvSyw"
}
}
}
]
}
The id value for each object in the items array should be the videoId value that you want.
api_key = 'YOUR_API_KEY'
api_service_name = 'youtube'
api_version = 'v3'
playlist_id = 'SOME_PLAYLIST_ID'
# build a connected client
youtube = googleapiclient.discovery.build(api_service_name, api_version, developerKey=api_key)
# make a request (note, only the 'snippet' part has been requested)
request = youtube.playlistItems().list(part=['snippet'], playlistId=playlist_id)
response = request.execute()
# scrape out the actual video ids (probably could be safer)
for (k, v) in response.items():
if(k == 'items'):
video_ids = [pli['snippet']['resourceId']['videoId'] for pli in v if pli['snippet']['resourceId']['kind']=='youtube#video']
print(video_ids)