I want to list all the movies available on YouTube (i.e. those available via //youtube.com/movies). I can see how to query those using API V2, but this has a limit of 1000 responses.
With the V3 api I can see the category for movies has id 30, but I can't work out how to get all movies with this category. The only category queries appear to search on guide categories, which are different.
Any clues on how I can get this list? Please help if you can!
I believe that you can get the autogenerated channels, related to movies, and use their id to get the playlists related to this channels and finally the items (videos..) from this playlists, that must be the videos related to the movies of the selected channels:
Retrieve movie channels:
Request
https://www.googleapis.com/youtube/v3/search?part=snippet&q=movies&type=channel&key={YOUR_API_KEY}
Partial response
"items": [
{
"id": {
"kind": "youtube#channel",
"channelId": "UCczhp4wznQWonO7Pb8HQ2MQ"
},
"kind": "youtube#searchResult",
"etag": "\"eTr3dHIt5_K9qdGtRKL-5XdpiQI/sQpwXP-0MUEZzOQx4F0yKj0eUR4\"",
"snippet": {
"publishedAt": "2005-12-15T03:07:36.000Z",
"channelId": "UCczhp4wznQWonO7Pb8HQ2MQ",
"title": "movies",
"description": "YouTube Movies (United States).",
"thumbnails": {
"default": {
"url": "http://i.ytimg.com/i/czhp4wznQWonO7Pb8HQ2MQ/1.jpg"
},
"medium": {
"url": "http://i.ytimg.com/i/czhp4wznQWonO7Pb8HQ2MQ/mq1.jpg"
},
"high": {
"url": "http://i.ytimg.com/i/czhp4wznQWonO7Pb8HQ2MQ/hq1.jpg"
}
}
}
},
e.g. Get the list of movies in channel "YouTube Movies (United States)"
Request
https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId=UCczhp4wznQWonO7Pb8HQ2MQ&key={YOUR_API_KEY}
Partial response:
{
"id": "PLjygWhZE6KY0Uhw12FsAc8raAClz0l71C",
"kind": "youtube#playlist",
"etag": "\"eTr3dHIt5_K9qdGtRKL-5XdpiQI/TWrkoCkmJvq14neCcutnApHMMgU\"",
"snippet": {
"publishedAt": "2012-12-06T20:11:40.000Z",
"channelId": "UCczhp4wznQWonO7Pb8HQ2MQ",
"title": "The Nicolas Cage Collection",
"description": "From panicked fathers to spirits of vengeance, Nicolas Cage has done it all.",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/nHiy8SVZdpU/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/nHiy8SVZdpU/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/nHiy8SVZdpU/hqdefault.jpg"
}
}
}
},
Get items from this playlist:
Request:
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=PLjygWhZE6KY0Uhw12FsAc8raAClz0l71C&key={YOUR_API_KEY}
Partial response:
{
"kind": "youtube#playlistItemListResponse",
"etag": "\"eTr3dHIt5_K9qdGtRKL-5XdpiQI/KSlqEnNGq36l47_k9W3fd79KfYQ\"",
"pageInfo": {
"totalResults": 15,
"resultsPerPage": 5
},
"nextPageToken": "CAUQAA",
"items": [
{
"id": "PLcBtbpFAOApiV34TU797yEFAUZuwhFrvJya3MqlZWkGM",
"kind": "youtube#playlistItem",
"etag": "\"eTr3dHIt5_K9qdGtRKL-5XdpiQI/C_xTa48Xof7giXobSula2vWX43A\"",
"snippet": {
"publishedAt": "2012-12-06T20:12:49.000Z",
"channelId": "UCczhp4wznQWonO7Pb8HQ2MQ",
"title": "Stolen",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/nHiy8SVZdpU/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/nHiy8SVZdpU/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/nHiy8SVZdpU/hqdefault.jpg"
}
},
"playlistId": "PLjygWhZE6KY0Uhw12FsAc8raAClz0l71C",
"position": 0,
"resourceId": {
"kind": "youtube#video",
"videoId": "nHiy8SVZdpU"
}
}
},
{
"id": "PLcBtbpFAOApiV34TU797yED-1zeMCoMGVxtVgtX9ZdsQ",
"kind": "youtube#playlistItem",
"etag": "\"eTr3dHIt5_K9qdGtRKL-5XdpiQI/LgSyqtZkwJXv6-2ajW0g-FsgddQ\"",
"snippet": {
"publishedAt": "2012-12-06T20:19:26.000Z",
"channelId": "UCczhp4wznQWonO7Pb8HQ2MQ",
"title": "Trespass",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/J_7Zug6ouy4/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/J_7Zug6ouy4/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/J_7Zug6ouy4/hqdefault.jpg"
}
},
"playlistId": "PLjygWhZE6KY0Uhw12FsAc8raAClz0l71C",
"position": 1,
"resourceId": {
"kind": "youtube#video",
"videoId": "J_7Zug6ouy4"
}
}
},
and in this way you can create the list of videos as you want
Here's my current answer - still working on it so I've not accepted it yet
I worked out the categoryId for Movies is 30. I then did a search for videos using this categoryId, and the query string "movie" (just because I need to put something). This gives more than 1000 results, and google limits queries to 1000 results even with the v3 api.
So I need to partition my query. I have been able to do this with publishedBefore and publishedAfter. Note these are upload dates and not release dates.
This gives me a list of movies.
Here's a sample query
https://www.googleapis.com/youtube/v3/search?nextPageToken=CDIQAA&publishedBefore=2010-02-01T00%3A00%3A00Z&maxResults=50&q=movie&videoCategoryId=30&part=id%2Csnippet&key=yourAPIKeyHere&type=video&publishedAfter=2010-01-01T00%3A00%3A00Z
Once I have the movie IDs I query the individual movie ids
https://www.googleapis.com/youtube/v3/videos?part=snippet%2CcontentDetails&maxResults=50&id=O7cSKNevYQc%2CN84-SoboM6c%2C9K_WO3lqDSc%2CWTJP0Z-bknc%2CdF9hwjeRbGE%2CPnefvJ9T1N0%2CDuM6B4yKgTU%2C0tI8iP2f58I%2Cr4lNJEnY0FA%2COFnMrx6yEcA%2CmUZUAeqOmbg%2CDjq0tHK-KTo%2CkY44nxk0qjg%2CcLYkUR5MY14%2CTZpcfYOOEXA%2C-0jA9DMX8Qs%2C2TQDV1m4X2s%2CBh3Tye1OQvk%2Ct5IwjMDVNz4%2CkOi88X6xeKg%2Ck53CuaAUtik%2CNaRuenqLb9g%2Cn9h-0Wgix7Q%2CQG8SiW2a_l0%2Cmk-D66Z1Ydg%2ClvmwofckpNc%2CgRQK4fTXfBM%2CPZHgLy48R3Q%2CwczeO0DVM0g%2CTpMDTG3dEYE%2C6JI8pN7BqEQ%2COv9yllk3hsY%2CsN09sfLPu0g%2CbfhLYJGN948%2CPiWusdK75Ys%2CeE5jh0YwTCY%2C_cIw3vr2Q18%2CSA4xg_k0aqI%2CUZdha0zTM6w%2CwUdkDSIBw94%2CAhR-LDSIOaI%2C1XMt40vJayU%2C83fPx5-aUL8%2CmJLjaKzu7PQ%2CZvj_zRGnwU0%2CtyIPMd7JXOA%2CToE10sC36KQ%2COVKXjOW6cD8%2CLPW1cXVjMrg&key=LALALA
I still then need to filter the results by looking at the following json in the results
"contentDetails": {
"duration": "PT1H35M14S",
"regionRestriction": {
"allowed": [
"US"
]
}
Unfortunately this still doesn't give me the movie year or director (which are useful for working out which movie this actually is), or the price (which, you know, people find interesting)
Related
I have noticed that all videos from the account, Kanye West - Topic, don't show up in the api results. Does anyone have a reason why or a solution to fix this? For example, when I use the api search GET https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCRY5dYsbIN5TylSbd7gVnZg&type=video&key={YOUR_API_KEY}, it says there are 961 total results but the items section is empty.
Your GET request is correct but it's missing additional field resources parameters, so it doesn't know what you want to retrieve. I've added the fields to your GET REQUEST using the Google API Explorer and here's what it looks like:
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCRY5dYsbIN5TylSbd7gVnZg&maxResults=50&q=%22Kanye+West%22&fields=etag%2CeventId%2Citems%2Ckind%2CnextPageToken%2CpageInfo%2CprevPageToken%2CregionCode%2CtokenPagination%2CvisitorId&key={API_KEY_HERE}
And the response was:
{
"kind": "youtube#searchListResponse",
"etag": "\"GM4ZnRh2gk1X1BLWgHklTm-3cgQ/6VdmXA4FhXjg08y58iRnmXZY7wQ\"",
"nextPageToken": "CDIQAA",
"regionCode": "PH",
"pageInfo": {
"totalResults": 841,
"resultsPerPage": 50
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"GM4ZnRh2gk1X1BLWgHklTm-3cgQ/VSzDMW_CqJw-OMjo_vzPR2P40eI\"",
"id": {
"kind": "youtube#channel",
"channelId": "UCRY5dYsbIN5TylSbd7gVnZg"
},
"snippet": {
"publishedAt": "2013-07-02T20:09:18.000Z",
"channelId": "UCRY5dYsbIN5TylSbd7gVnZg",
"title": "Kanye West - Topic",
"description": "Kanye Omari West is an American rapper, songwriter, record producer, fashion designer, and entrepreneur. Born in Atlanta and raised in Chicago, West first ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/i/RY5dYsbIN5TylSbd7gVnZg/1.jpg"
},
"medium": {
"url": "https://i.ytimg.com/i/RY5dYsbIN5TylSbd7gVnZg/mq1.jpg"
},
"high": {
"url": "https://i.ytimg.com/i/RY5dYsbIN5TylSbd7gVnZg/hq1.jpg"
}
},
"channelTitle": "Kanye West - Topic",
"liveBroadcastContent": "none"
}
.. (long list below)
If you want to conduct additonal test, use the Youtube API Explorer.
Why is it when I search for a channel by ID https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id=UU-tdS40X5ld-a4KfarLJuDw&key=[YOUR_API_KEY] I get no items returned.
But when I search by userName, it returns the channel ID that I just searched for https://www.googleapis.com/youtube/v3/channels?part=contentDetails&forUsername=washingtonstateuniv&key=[YOUR_API_KEY]
when I search for a channel by ID .. I get no items returned.
Give the Try-it section for channels.list a try. I'm able to fetch JSON response by using these parameters:
part->contentDetails
id-> yourchannel ID
Authorize and Execute
The response it returned is not empty at all.
{
"kind": "youtube#channelListResponse",
"etag": "\"I_8xdZu766_FSaexEaDXTIfEWc0/FiuYcDu7WFmoFVcLDRvENYGl_tQ\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"I_8xdZu766_FSaexEaDXTIfEWc0/QjMybH99xT3x-znrh2Yerx_0DWk\"",
"id": "{my channel id}",
"snippet": {
"title": "{my channel name}",
"description": "",
"publishedAt": "2011-10-10T15:30:40.000Z",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/-EN5H1HDHqIU/ABCDEFGHIJK/ABCDEFGHIJK/l2gqeYg94P8/s88-c-k-no-mo-rj-c0xffffff/photo.jpg"
},
"medium": {
"url": "https://yt3.ggpht.com/-EN5H1HDHqIU/ABCDEFGHIJK/ABCDEFGHIJK/l2gqeYg94P8/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
},
"high": {
"url": "https://yt3.ggpht.com/-EN5H1HDHqIU/ABCDEFGHIJK/ABCDEFGHIJK/l2gqeYg94P8/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
}
},
"localized": {
"title": "{my channel name}",
"description": ""
}
}
}
]
}
That's a lot of results for me.
But when I search by userName, it returns the channel ID that I just
searched for.
In the channels.list try-it docs above, forUsername is defined as the forUsername parameter specifies a YouTube username, thereby requesting the channel associated with that username. So I think it's doing it's job.
Additional note on forUsername parameter is that's it's used to translate your arbitrary legacy YouTube username, that's the old Youtube accounts, into a channel ID using v3 of the API. More of that in Work with Channel IDs guide.
when I search by userName, it returns the channel ID that I just
searched for
You miss the important part to search by forUsername or channelID. That is snippet part, not contentDetails.
by forUsername :
https://www.googleapis.com/youtube/v3/channels?&part=snippet,id&forUsername=RealMiBs&title&key={YOUR_API_KEY}
by id channel:
https://www.googleapis.com/youtube/v3/channels?&part=snippet,id&id=UC_pwIXKXNm5KGhdEVzmY60A&title&key={YOUR_API_KEY}
That will exactly returned to like below:
{
"kind": "youtube#channelListResponse",
"etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/VnicD0AYsCI7KlKKcdsmdIlWUMs\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/Nl4tuuOFwuPOdHmP_Ky3vuIQ2Gg\"",
"id": "UC_pwIXKXNm5KGhdEVzmY60A",
"snippet": {
"title": "CJENMMUSIC Official", <== Channel Name
"description": "Asia's No.1 Entertainment & Media Company", <== Channel Desctiption
"customUrl": "cjenmmusic", <=== Channel URL who has been qualified - to and for - claimed it
"publishedAt": "2011-03-25T04:48:40.000Z",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/-QMkGdFbhrOc/AAAAAAAAAAI/AAAAAAAAAAA/6boUKax-3EA/s88-c-k-no-mo-rj-c0xffffff/photo.jpg"
},
"medium": {
"url": "https://yt3.ggpht.com/-QMkGdFbhrOc/AAAAAAAAAAI/AAAAAAAAAAA/6boUKax-3EA/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
},
"high": {
"url": "https://yt3.ggpht.com/-QMkGdFbhrOc/AAAAAAAAAAI/AAAAAAAAAAA/6boUKax-3EA/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
}
},
"localized": {
"title": "CJENMMUSIC Official",
"description": "Asia's No.1 Entertainment & Media Company"
}
}
}
]
}
While if you just pointing to contentDetails, it will return to almost nothing:
{
"kind": "youtube#channelListResponse",
"etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/C7SnOhT2c-Fs2R9f6JlxlOPWc34\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/3RTKaEQC9GX8c58R2Bhd8G1y3zM\"",
"id": "UC_pwIXKXNm5KGhdEVzmY60A",
"contentDetails": { <============== detail contents
"relatedPlaylists": {
"uploads": "UU_pwIXKXNm5KGhdEVzmY60A",
"watchHistory": "HL",
"watchLater": "WL"
}
}
}
]
}
I had created an live event on youtube and i had associated a custom ingestion (live stream) to that live event.
I am able to get the list of live events by calling
https://www.googleapis.com/youtube/v3/liveBroadcasts?part=snippet&broadcastStatus=all
Response
{
"kind": "youtube#liveBroadcastListResponse",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/6LS8J5LIkMcXRAIUEViaRonO_jk\"",
"items": [
{
"kind": "youtube#liveBroadcast",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/eSW3gnAC5A4iNg4xj-r8vvP4ha8\"",
"id": "M96Pswa174I",
"snippet": {
"publishedAt": "2015-08-27T09:26:52.000Z",
"channelId": "UCx_ZkmygOl4Bc0PHV8zXeag",
"title": "My new event",
"description": "This is test event",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/M96Pswa174I/default_live.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/M96Pswa174I/mqdefault_live.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/M96Pswa174I/hqdefault_live.jpg",
"width": 480,
"height": 360
}
},
"scheduledStartTime": "2015-08-27T09:30:00.000Z",
"isDefaultBroadcast": false
}
}
]
}
then i am able to get the live stream by calling
https://www.googleapis.com/youtube/v3/liveStreams?part=cdn%2Csnippet&mine=true
Response
- SHOW HEADERS -
{
"kind": "youtube#liveStreamListResponse",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/ctbzD5B9MI-wBMxDXCWCto2oFO8\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#liveStream",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/LEFmnjMqvHydtqmxovlaXCai3vM\"",
"id": "x_ZkmygOl4Bc0PHV8zXeag1440668944469033",
"snippet": {
"publishedAt": "2015-08-27T09:49:04.000Z",
"channelId": "UCx_ZkmygOl4Bc0PHV8zXeag",
"title": "My new stream",
"description": "this is demo stream",
"isDefaultStream": false
},
"cdn": {
"format": "720p_hfr",
"ingestionType": "rtmp",
"ingestionInfo": {
"streamName": "rathodm63.6584-jszu-8p4h-43yg",
"ingestionAddress": "rtmp://a.rtmp.youtube.com/live2",
"backupIngestionAddress": "rtmp://b.rtmp.youtube.com/live2?backup=1"
}
}
}
]
}
but how to identify that this steam belongs to above specified live event ?
You must use LiveBroadcasts.bind to bind a YouTube broadcast to a stream. Note that a broadcast can only be bound to one video stream, although a video stream may be bound to more than one broadcast. Then, you can use the LiveBroadcasts.list request and check the contentDetails.boundStreamId, which will be the stream associated with that livebroadcast. You'll have to specify part=contentDetails if you want to do this through an HTTP request.
I was trying to fetch different youtube channels on the basis of the regionCode.
Trying to fetch indian youtube channels:
https://www.googleapis.com/youtube/v3/search?part=snippet&type=channel®ionCode=IN&maxResults=5&key={API_KEY}
Trying to fetch Malaysian youtube channels:
https://www.googleapis.com/youtube/v3/search?part=snippet&type=channel®ionCode=MY&maxResults=5&key={API_KEY}
I am getting same result for both of this requests. Why this is happening?
{
"kind": "youtube#searchListResponse",
"etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/EiqwT6pG1EkwVEl17s1_qudvkmk\"",
"nextPageToken": "CAUQAA",
"pageInfo": {
"totalResults": 1000000,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/smpwgLdS9Og11NhpzRYcy37a9V8\"",
"id": {
"kind": "youtube#channel",
"channelId": "UCrFiA0hztL9e8zTi_qBuW4w"
},
"snippet": {
"publishedAt": "2013-03-19T20:35:41.000Z",
"channelId": "UCrFiA0hztL9e8zTi_qBuW4w",
"title": "EeOneGuy",
"description": "Просто делаю ролики =)",
"thumbnails": {
"default": {
"url": "https://lh6.googleusercontent.com/-ZPtgaY_lFDY/AAAAAAAAAAI/AAAAAAAAAAA/U_8gJcnIMiE/photo.jpg"
},
"medium": {
"url": "https://lh6.googleusercontent.com/-ZPtgaY_lFDY/AAAAAAAAAAI/AAAAAAAAAAA/U_8gJcnIMiE/photo.jpg"
},
"high": {
"url": "https://lh6.googleusercontent.com/-ZPtgaY_lFDY/AAAAAAAAAAI/AAAAAAAAAAA/U_8gJcnIMiE/photo.jpg"
}
},
"channelTitle": "EeOneGuy",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/g4m9Kno2zbU7BMIEUbffxDlyvZI\"",
"id": {
"kind": "youtube#channel",
"channelId": "UC7MO7ngSqsBcvQvxNf-kpWg"
},
"snippet": {
"publishedAt": "2013-06-04T17:39:49.000Z",
"channelId": "UC7MO7ngSqsBcvQvxNf-kpWg",
"title": "The Right to Research Coalition",
"description": "The Right to Research Coalition is a coalition of 80 undergraduate and graduate student organisations from across the world. Together we educate and ...",
"thumbnails": {
"default": {
"url": "https://lh5.googleusercontent.com/-p0RT2XiO3_0/AAAAAAAAAAI/AAAAAAAAAAA/tdAJTswPnB0/photo.jpg"
},
"medium": {
"url": "https://lh5.googleusercontent.com/-p0RT2XiO3_0/AAAAAAAAAAI/AAAAAAAAAAA/tdAJTswPnB0/photo.jpg"
},
"high": {
"url": "https://lh5.googleusercontent.com/-p0RT2XiO3_0/AAAAAAAAAAI/AAAAAAAAAAA/tdAJTswPnB0/photo.jpg"
}
},
"channelTitle": "R2RCvideo",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/nWC7qhbPZRH0qyEBOcWdFR8TI5k\"",
"id": {
"kind": "youtube#channel",
"channelId": "UCmSSq5573Ru9asXsXykgqTw"
},
"snippet": {
"publishedAt": "2014-10-12T02:26:56.000Z",
"channelId": "UCmSSq5573Ru9asXsXykgqTw",
"title": "Toys Games TV",
"description": "Welcome to Toys Games TV Channel! Looking for a safe channel for your kids? Look no further, on TGTV we review primarily Disney, PBS & Sprout character ...",
"thumbnails": {
"default": {
"url": "https://lh3.googleusercontent.com/-5qqjMUWhRow/AAAAAAAAAAI/AAAAAAAAAAA/2la9IA5DNhU/photo.jpg"
},
"medium": {
"url": "https://lh3.googleusercontent.com/-5qqjMUWhRow/AAAAAAAAAAI/AAAAAAAAAAA/2la9IA5DNhU/photo.jpg"
},
"high": {
"url": "https://lh3.googleusercontent.com/-5qqjMUWhRow/AAAAAAAAAAI/AAAAAAAAAAA/2la9IA5DNhU/photo.jpg"
}
},
"channelTitle": "ToysGamesTV",
"liveBroadcastContent": "upcoming"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/enqEI6qDr8UfYcjixI9Cjpd6SU0\"",
"id": {
"kind": "youtube#channel",
"channelId": "UCtjLPHCyI5V-xuumAXzAizA"
},
"snippet": {
"publishedAt": "2008-06-05T04:13:13.000Z",
"channelId": "UCtjLPHCyI5V-xuumAXzAizA",
"title": "UNUChannel",
"description": "Channel produced by the United Nations University (UNU). The overarching goal of the United Nations University is to contribute to global sustainable ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/i/tjLPHCyI5V-xuumAXzAizA/1.jpg"
},
"medium": {
"url": "https://i.ytimg.com/i/tjLPHCyI5V-xuumAXzAizA/mq1.jpg"
},
"high": {
"url": "https://i.ytimg.com/i/tjLPHCyI5V-xuumAXzAizA/hq1.jpg"
}
},
"channelTitle": "UNUChannel",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/44t2atyjsxpSOVj7OfeK9GTfy0M\"",
"id": {
"kind": "youtube#channel",
"channelId": "UCJ7-0_cR9HiA9iX8n3kugcg"
},
"snippet": {
"publishedAt": "2010-06-29T15:08:02.000Z",
"channelId": "UCJ7-0_cR9HiA9iX8n3kugcg",
"title": "Naturhistoriska riksmuseet",
"description": "Naturhistoriska riksmuseets och Cosmonovas YouTube-kanal.",
"thumbnails": {
"default": {
"url": "https://lh5.googleusercontent.com/-OItSjQXSj_c/AAAAAAAAAAI/AAAAAAAAAAA/ybdmiik-0eA/photo.jpg"
},
"medium": {
"url": "https://lh5.googleusercontent.com/-OItSjQXSj_c/AAAAAAAAAAI/AAAAAAAAAAA/ybdmiik-0eA/photo.jpg"
},
"high": {
"url": "https://lh5.googleusercontent.com/-OItSjQXSj_c/AAAAAAAAAAI/AAAAAAAAAAA/ybdmiik-0eA/photo.jpg"
}
},
"channelTitle": "SthlmNaturhistoriska",
"liveBroadcastContent": "none"
}
}
]
}
Thanks in advance. Any help would be much appreciated.
From the documentation:
regionCode - (string) The regionCode parameter instructs the API to return
search results for the specified country. The parameter value is an
ISO 3166-1 alpha-2 country code.
It looks like specifying the regionCode returns search results as if you were in that country, not for videos/channels that are associated with that country. For example, if you specified CN (China) as the region code, you wouldn't get results for videos that have been blocked in China.
It seems that there's no good way to get all channels that belong to a particular country. What you could do is execute the search.list() with your specified search criteria and set type=Channel. Then, based on the response, issue a request to channels.list() to get the country and compare to see if it is from that specific country. It's pretty inefficient, and while I was trying to test a similar way of doing it, I found that I can set my country in the "About" section of my channel. However, since the field is optional, there's no guarantee that users are actually setting this for their channels, so ultimately it's hard for you to get the information you're looking for.
I tried to use this:
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet,contentDetails&{playlist_id}&key={key}&maxResults=50
and
https://www.googleapis.com/youtube/v3/search?part=snippet&q=YouTube+Data+API&type=video&videoCaption=closedCaption&key={key}&maxResults=50
It says in the documentation it is contentDetails.duration but this doesn't seem to be present in the data I receive.
In order to get the detailed information about a video in a playlist, you will need to hit the Videos.list method for every video in that playlist with the snippet and contentDetails values for part:
Request:
HTTP GET https://www.googleapis.com/youtube/v3/videos?part=snippet%2C+contentDetails&id=AKiiekaEHhI&key={YOUR_API_KEY}
Response (for id=AKiiekaEHhI):
{
"kind": "youtube#videoListResponse",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/Qz22l3E04nR4kuY2SGE5M_d1BMM\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/8X_byN22HJTh5FJyoMH9bFGR_Og\"",
"id": "AKiiekaEHhI",
"snippet": {
"publishedAt": "2015-05-04T10:01:43.000Z",
"channelId": "UCkvdZX3SVgfDW8ghtP1L2Ug",
"title": "The Legend of Zelda: Majora's Mask With Glitches - Part 17: Going Against the Flow",
"description": "Follow me on Twitter! http://twitter.com/swordlesslink\n\nFollow me on TwitchTV for live video game streaming! http://twitch.tv/swordlesslink",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/AKiiekaEHhI/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/AKiiekaEHhI/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/AKiiekaEHhI/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/AKiiekaEHhI/sddefault.jpg",
"width": 640,
"height": 480
}
},
"channelTitle": "Swordless Link",
"categoryId": "20",
"liveBroadcastContent": "none",
"localized": {
"title": "The Legend of Zelda: Majora's Mask With Glitches - Part 17: Going Against the Flow",
"description": "Follow me on Twitter! http://twitter.com/swordlesslink\n\nFollow me on TwitchTV for live video game streaming! http://twitch.tv/swordlesslink"
}
},
"contentDetails": {
"duration": "PT17M30S",
"dimension": "2d",
"definition": "hd",
"caption": "false",
"licensedContent": true
}
}
]
}
The duration of the content can be found as the object for the duration key in the contentDetails dictionary.
The categoryId maps to your video category, which you will have to look up using the VideoCategories.list method.
Request:
HTTP GET https://www.googleapis.com/youtube/v3/videoCategories?part=snippet&id={CATEGORY_ID}&key={YOUR_API_KEY}
Response (for id=20:
{
"kind": "youtube#videoCategoryListResponse",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/cVclmqPmb6Xbwij8SctXRUrSVhw\"",
"items": [
{
"kind": "youtube#videoCategory",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/WmA0qYEfjWsAoyJFSw2zinhn2wM\"",
"id": "20",
"snippet": {
"channelId": "UCBR8-60-B28hp2BmDPdntcQ",
"title": "Gaming",
"assignable": true
}
}
]
}
The object for the title key in the snippet dictionary returns the String value of the video category that you want.
If you check search resource, you'll see its not in that response.
This was actually a feature request in: https://code.google.com/p/gdata-issues/issues/detail?id=4294
You can follow up that issue.