Friday, 8 May 2015

Youtube v3 API Sample API Requests and Response - Search Videos - Get Video Details

Youtube v3 API Sample API Requests and Response - Search Videos - Get Video Details


For youtube v3 API, you must need an API_KEY for video search, get video details, upload video and delete video etc.
In each request, you need to pass the APK_KEY to get the records, If you didn't pass the API_KEY, you will not get the response from youtube api.

In Youtube V2 API_KEY is not required, but its is compulsary for youtube V3 API.
google has stopped the youtube v2 API so you must use V3 API.

If you don't have API_KEY, please get the API Key from http://code.google.com/apis/console#access .
You must need google account for youtube v3 API.
Youtube v3 API Sample API Requests and Response - Search Video List - Get Video Details


Now, I am assuming you have valid API_KEY. if you have added referer while creating API, then you can use API_KEY for that domain only. Yeah you can add multiple domain for 1 key.
Suppose we have following API_KEY.
API_KEY: AIzaSyBqXp0Uo2ktJcMRpL_ZwF5inLTWZfsCYqY

Also you must enable the "YouTube Data API" from google console for the same key.

Get List of youtube Videos (By Default It will gives 4 videos)
https://www.googleapis.com/youtube/v3/search?part=snippet&key=AIzaSyBqXp0Uo2ktJcMRpL_ZwF5inLTWZfsCYqY


Get List of youtube videos (Search 40 videos)
https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=40&key=AIzaSyBqXp0Uo2ktJcMRpL_ZwF5inLTWZfsCYqY


Get List of youtube videos (Search 40 videos + having keyword "sports" )
https://www.googleapis.com/youtube/v3/search?part=snippet&q=sports&maxResults=40&key=AIzaSyBqXp0Uo2ktJcMRpL_ZwF5inLTWZfsCYqY


Get List of youtube videos( Search with 100km of 37.42307,-122.08427(lat/long)
https://www.googleapis.com/youtube/v3/search?locationRadius=100km&part=snippet&location=37.42307%2C-122.08427&type=video&key=AIzaSyBqXp0Uo2ktJcMRpL_ZwF5inLTWZfsCYqY


Get List of youtube videos (search videos which are tags with sports [videoCategoryId=17])
https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&videoCategoryId=17&key=AIzaSyBqXp0Uo2ktJcMRpL_ZwF5inLTWZfsCYqY


Response Format:
{"kind":"youtube#searchListResponse","etag":"\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/okahf16vRr9O67w1AX2xksAkmDI\"","nextPageToken":"CAUQAA","pageInfo":{"totalResults":1000000,"resultsPerPage":5},"items":[{"kind":"youtube#searchResult","etag":"\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/EIQjGNXfg22wA149MrmBxBM3QX4\"","id":{"kind":"youtube#video","videoId":"a2RA0vsZXf8"},"snippet":{"publishedAt":"2010-11-21T05:14:05.000Z","channelId":"UCplkk3J5wrEl0TNrthHjq4Q","title":"\"Just A Dream\" by Nelly - Sam Tsui & Christina Grimmie","description":"Check out our epic song with Coke Bottles! https://www.youtube.com/watch?v=ZzuRvzsNpTU Hope you guys like this duet between Christina Grimmie and Sam ...","thumbnails":{"default":{"url":"https://i.ytimg.com/vi/a2RA0vsZXf8/default.jpg"},"medium":{"url":"https://i.ytimg.com/vi/a2RA0vsZXf8/mqdefault.jpg"},"high":{"url":"https://i.ytimg.com/vi/a2RA0vsZXf8/hqdefault.jpg"}},"channelTitle":"KurtHugoSchneider","liveBroadcastContent":"none"}},{"kind":"youtube#searchResult","etag":"\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/3bB0h6KJXx-TPbAqXKd5nADWGX0\"","id":{"kind":"youtube#video","videoId":"Ahha3Cqe_fk"},"snippet":{"publishedAt":"2011-11-11T18:37:24.000Z","channelId":"UC-8Q-hLdECwQmaWNwXitYDw","title":"Katy Perry - The One That Got Away","description":"Sometimes you promise someone forever but it doesn't work out that way. Watch Katy Perry and Diego Luna star in the sixth chapter of the “Teenage Dream” ...","thumbnails":{"default":{"url":"https://i.ytimg.com/vi/Ahha3Cqe_fk/default.jpg"},"medium":{"url":"https://i.ytimg.com/vi/Ahha3Cqe_fk/mqdefault.jpg"},"high":{"url":"https://i.ytimg.com/vi/Ahha3Cqe_fk/hqdefault.jpg"}},"channelTitle":"KatyPerryVEVO","liveBroadcastContent":"none"}},{"kind":"youtube#searchResult","etag":"\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/VZLQn8wfLOJ60oe6Bced9ryD7Kg\"","id":{"kind":"youtube#video","videoId":"NV7xJ73_eeM"},"snippet":{"publishedAt":"2014-11-17T14:00:19.000Z","channelId":"UCMu5gPmKp5av0QCAajKTMhw","title":"Romeo and Juliet vs Bonnie and Clyde. Epic Rap Battles of History Season 4","description":"Download on iTunes ▻ http://bit.ly/1yN7aai ◅ Season 3 Autographed CDs available at ▻ http://shop.erb.fm ◅ Subscribe for more battles! http://bit.ly/1ElwJ40 ...","thumbnails":{"default":{"url":"https://i.ytimg.com/vi/NV7xJ73_eeM/default.jpg"},"medium":{"url":"https://i.ytimg.com/vi/NV7xJ73_eeM/mqdefault.jpg"},"high":{"url":"https://i.ytimg.com/vi/NV7xJ73_eeM/hqdefault.jpg"}},"channelTitle":"ERB","liveBroadcastContent":"none"}},{"kind":"youtube#searchResult","etag":"\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/IN61vHPZ3FNoK9mme_Kf9E0U50c\"","id":{"kind":"youtube#video","videoId":"XjwZAa2EjKA"},"snippet":{"publishedAt":"2013-11-20T08:03:53.000Z","channelId":"UC-8Q-hLdECwQmaWNwXitYDw","title":"Katy Perry - Unconditionally (Official)","description":"Download \"Unconditionally\" from Katy Perry's 'PRISM': http://smarturl.it/PRISM Official video for Katy Perry's \"Unconditionally\" directed by Brent Bonacorso and ...","thumbnails":{"default":{"url":"https://i.ytimg.com/vi/XjwZAa2EjKA/default.jpg"},"medium":{"url":"https://i.ytimg.com/vi/XjwZAa2EjKA/mqdefault.jpg"},"high":{"url":"https://i.ytimg.com/vi/XjwZAa2EjKA/hqdefault.jpg"}},"channelTitle":"KatyPerryVEVO","liveBroadcastContent":"none"}},{"kind":"youtube#searchResult","etag":"\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/gKZhz62FdXndZR7dJdi_PDTpe9U\"","id":{"kind":"youtube#video","videoId":"-kWHMH2kxXs"},"snippet":{"publishedAt":"2014-11-01T04:10:36.000Z","channelId":"UC8-Th83bH_thdKZDJCrn88g","title":"Wheel of Impressions with Kevin Spacey","description":"In this Halloween edition of Wheel of Impressions, Jimmy and Kevin take turns doing random celebrity impersonations, such as Christopher Walken talking ...","thumbnails":{"default":{"url":"https://i.ytimg.com/vi/-kWHMH2kxXs/default.jpg"},"medium":{"url":"https://i.ytimg.com/vi/-kWHMH2kxXs/mqdefault.jpg"},"high":{"url":"https://i.ytimg.com/vi/-kWHMH2kxXs/hqdefault.jpg"}},"channelTitle":"latenight","liveBroadcastContent":"none"}}]}



Get Youtube Videos by Channel
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCv7IjJclSgpfGUHnG171ovw&order=date&key=AIzaSyBpu8hgnXbkqFVWrAvwRUEz7T13ii3I7WM
Response Format:
{"kind":"youtube#searchListResponse","etag":"\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/q7tdIBpMwbnE_LWyfCaBtuEXMes\"","nextPageToken":"CAUQAA","pageInfo":{"totalResults":296,"resultsPerPage":5},"items":[{"kind":"youtube#searchResult","etag":"\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/kvgjXpyJJ1CVnWs7i6kI_3-X0go\"","id":{"kind":"youtube#video","videoId":"drsH-pNpxho"},"snippet":{"publishedAt":"2015-04-23T14:21:19.000Z","channelId":"UCv7IjJclSgpfGUHnG171ovw","title":"A4 Pain - Painkiller #7 by Fez","description":"Insane new episode from A4 Pain Player: A4 Pain https://www.youtube.com/channel/UCVSS_0NReZbN3phT1OSKseQ Editor: Fez TOS ...","thumbnails":{"default":{"url":"https://i.ytimg.com/vi/drsH-pNpxho/default.jpg"},"medium":{"url":"https://i.ytimg.com/vi/drsH-pNpxho/mqdefault.jpg"},"high":{"url":"https://i.ytimg.com/vi/drsH-pNpxho/hqdefault.jpg"}},"channelTitle":"TheApokalypse4","liveBroadcastContent":"none"}},{"kind":"youtube#searchResult","etag":"\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/t-udHC0CmSmK9Ej_q8KQgfHpyAo\"","id":{"kind":"youtube#video","videoId":"4kq8pW3ML0M"},"snippet":{"publishedAt":"2015-04-09T20:09:46.000Z","channelId":"UCv7IjJclSgpfGUHnG171ovw","title":"Apokalypse4 Killcams of the week - Episode 12","description":"Yes this is a weekly, episode we're trying to bring out more content for you guys, this is a example. Hope you enjoy! [CLICK SHOW MORE] This weeks winners!","thumbnails":{"default":{"url":"https://i.ytimg.com/vi/4kq8pW3ML0M/default.jpg"},"medium":{"url":"https://i.ytimg.com/vi/4kq8pW3ML0M/mqdefault.jpg"},"high":{"url":"https://i.ytimg.com/vi/4kq8pW3ML0M/hqdefault.jpg"}},"channelTitle":"TheApokalypse4","liveBroadcastContent":"none"}},{"kind":"youtube#searchResult","etag":"\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/2_P60vNc53lyEX63yeKf_wlXYSk\"","id":{"kind":"youtube#video","videoId":"faizfXUbCAc"},"snippet":{"publishedAt":"2015-04-05T15:35:47.000Z","channelId":"UCv7IjJclSgpfGUHnG171ovw","title":"Apokalypse4 Challenges you - Episode 13","description":"Winner's chosen on the 1st of May, submit your ONLINE responses through twitter to @tehapokalypse4 and follow us for further information, good luck guys!","thumbnails":{"default":{"url":"https://i.ytimg.com/vi/faizfXUbCAc/default.jpg"},"medium":{"url":"https://i.ytimg.com/vi/faizfXUbCAc/mqdefault.jpg"},"high":{"url":"https://i.ytimg.com/vi/faizfXUbCAc/hqdefault.jpg"}},"channelTitle":"TheApokalypse4","liveBroadcastContent":"none"}},{"kind":"youtube#searchResult","etag":"\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/JVw8gcWNDBq6A0k3NzNYydX7n4A\"","id":{"kind":"youtube#video","videoId":"vHTMfV7sJVg"},"snippet":{"publishedAt":"2015-03-25T16:10:24.000Z","channelId":"UCv7IjJclSgpfGUHnG171ovw","title":"A4 Sponge: Cleaning up - Episode 1","description":"Insane feeder and editor collaborate and produce a insane episode, enjoy guys! Subscribe :) http://bit.ly/SubToA4 10000 Teamtage ...","thumbnails":{"default":{"url":"https://i.ytimg.com/vi/vHTMfV7sJVg/default.jpg"},"medium":{"url":"https://i.ytimg.com/vi/vHTMfV7sJVg/mqdefault.jpg"},"high":{"url":"https://i.ytimg.com/vi/vHTMfV7sJVg/hqdefault.jpg"}},"channelTitle":"TheApokalypse4","liveBroadcastContent":"none"}},{"kind":"youtube#searchResult","etag":"\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/imFn4cchjV1Gbp9F2zt9P-FgIvU\"","id":{"kind":"youtube#video","videoId":"AAMk41lxuyA"},"snippet":{"publishedAt":"2015-03-09T19:47:21.000Z","channelId":"UCv7IjJclSgpfGUHnG171ovw","title":"TheFantastic4 - ft. Gibby, Frizzy, Metal, Pregs by Cayzuh","description":"the ex a4 players return one last time. gibby https://www.youtube.com/user/ByGibbio frizzy https://www.youtube.com/user/OnyxFreeZy metal ...","thumbnails":{"default":{"url":"https://i.ytimg.com/vi/AAMk41lxuyA/default.jpg"},"medium":{"url":"https://i.ytimg.com/vi/AAMk41lxuyA/mqdefault.jpg"},"high":{"url":"https://i.ytimg.com/vi/AAMk41lxuyA/hqdefault.jpg"}},"channelTitle":"TheApokalypse4","liveBroadcastContent":"none"}}]}




Get youtube video Detail
To get the youtube video detail, you must have an valid youtube video.
https://www.googleapis.com/youtube/v3/videos?id=a2RA0vsZXf8&part=snippet,statistics&key=AIzaSyBqXp0Uo2ktJcMRpL_ZwF5inLTWZfsCYqY
Response Format:
{"kind":"youtube#videoListResponse","etag":"\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/5O69VO4RLDboG2ONvOiRwnoX77I\"","pageInfo":{"totalResults":1,"resultsPerPage":1},"items":[{"kind":"youtube#video","etag":"\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/7xlJyY3lj1NCugehSg-sBnEM0YQ\"","id":"a2RA0vsZXf8","snippet":{"publishedAt":"2010-11-21T04:52:18.000Z","channelId":"UCplkk3J5wrEl0TNrthHjq4Q","title":"\"Just A Dream\" by Nelly - Sam Tsui & Christina Grimmie","description":"Check out our epic song with Coke Bottles! https://www.youtube.com/watch?v=ZzuRvzsNpTU\n\nHope you guys like this duet between Christina Grimmie and Sam Tsui on \"Just A Dream\" originally by Nelly!\n\nAnd if you don't know Christina, definitely check out her stuff and subscribe to her, because she rocks!!\nhttp://www.youtube.com/zeldaxlove64\n\nShare this on Facebook!  http://on.fb.me/JustADreamSamChristina\n\nWe just opened an online store with shirts, cd's and other cool stuff here:\nhttp://www.kurthugoschneider.com/store\n\n\n--------------\n\nLinks\n\nKURT SCHNEIDER\nFacebook- http://www.facebook.com/KurtHugoSchneider\nTwitter- http://www.twitter.com/KurtHSchneider\n\nSAM TSUI\nFacebook- http://www.facebook.com/SamTsuiMusic\nTwitter- http://www.twitter.com/SamuelTsui\n\n---------------\n\n'Just A Dream' (originally Performed By Nelly)\nWritten By: Cornell Haynes, Frank Romano, Jim Jonsin, James Scheffer, Richard Butler\nPublished By: Universal Music Publishing / EMI Music Publishing / Reach Global Inc.","thumbnails":{"default":{"url":"https://i.ytimg.com/vi/a2RA0vsZXf8/default.jpg","width":120,"height":90},"medium":{"url":"https://i.ytimg.com/vi/a2RA0vsZXf8/mqdefault.jpg","width":320,"height":180},"high":{"url":"https://i.ytimg.com/vi/a2RA0vsZXf8/hqdefault.jpg","width":480,"height":360},"standard":{"url":"https://i.ytimg.com/vi/a2RA0vsZXf8/sddefault.jpg","width":640,"height":480},"maxres":{"url":"https://i.ytimg.com/vi/a2RA0vsZXf8/maxresdefault.jpg","width":1280,"height":720}},"channelTitle":"Kurt Hugo Schneider","categoryId":"10","liveBroadcastContent":"none","localized":{"title":"\"Just A Dream\" by Nelly - Sam Tsui & Christina Grimmie","description":"Check out our epic song with Coke Bottles! https://www.youtube.com/watch?v=ZzuRvzsNpTU\n\nHope you guys like this duet between Christina Grimmie and Sam Tsui on \"Just A Dream\" originally by Nelly!\n\nAnd if you don't know Christina, definitely check out her stuff and subscribe to her, because she rocks!!\nhttp://www.youtube.com/zeldaxlove64\n\nShare this on Facebook!  http://on.fb.me/JustADreamSamChristina\n\nWe just opened an online store with shirts, cd's and other cool stuff here:\nhttp://www.kurthugoschneider.com/store\n\n\n--------------\n\nLinks\n\nKURT SCHNEIDER\nFacebook- http://www.facebook.com/KurtHugoSchneider\nTwitter- http://www.twitter.com/KurtHSchneider\n\nSAM TSUI\nFacebook- http://www.facebook.com/SamTsuiMusic\nTwitter- http://www.twitter.com/SamuelTsui\n\n---------------\n\n'Just A Dream' (originally Performed By Nelly)\nWritten By: Cornell Haynes, Frank Romano, Jim Jonsin, James Scheffer, Richard Butler\nPublished By: Universal Music Publishing / EMI Music Publishing / Reach Global Inc."}},"statistics":{"viewCount":"96352554","likeCount":"804825","dislikeCount":"8957","favoriteCount":"0","commentCount":"132350"}}]}