Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excessive requests required to access viewCount in YouTube v3 API search request

I am currently in the process of testing out the YouTube v3 API... I have a search results view in my mobile app that displays video results requiring the following fields:

title, author, views, description, thumbnail

In v2 a request to:

https://gdata.youtube.com/feeds/api/videos?q=bugatti&orderby=published&max-results=10&v=2&alt=jsonc

Returns the following response for a video entry:

{
    "id": "rdprvN3g3EU",
    "uploaded": "2013-02-11T12:49:05.000Z",
    "updated": "2013-02-11T12:49:05.000Z",
    "uploader": "thelongsixteen",
    "category": "Games",
    "title": "GTA IV Mods: Most Wanted #29 (German) (HD) - Ford Fiesta HFHV von Ken Block",
    "description": "Wenn euch das Video gefallen hat dann hinterlasst bitte ein ganz brutalen Like. :D Es hilft mir und dem Projekt sehr weiter zu machen. ^_^ » Grand Theft Auto IV Most Wanted Playlist: www.youtube.com » Mehr Videos findet ihr hier: www.youtube.com » Left 4 Liberty Infection v5.1 (Halloween Special): www.youtube.com Eine kleine Info über dieses Projekt: In diesem Projekt nehme ich ein bestimmtes Fahrzeug wie zB den Hummer H2 und versuche vom Flughafen aus zum Alderny Staatsgefängnis zu kommen und der schwierigste Part daran ist: 6 Star Wanted! :O Ich fahre jedesmal eine bestimmte Route um das Ziel zu erreichen und werde sehen wie es die Polizei genießen wird mich gegen alles zu drücken was nicht auf 3 auf dem Baum ist. Ich wünsche euch viel Spaß mit dem Video und wie immer Sweet Lovin! :D Die Mods: Grand Theft Auto Ultimate Vehicle Pack V9 (TBOGT/EPM Support) www.gta4-mods.com Das Video von dem Car Pack www.youtube.com ChinaGreenElvis ENB 4 for GTA IV and EFLC www.gta4-mods.com Color Radio HUD www.gta4-mods.com Bigger and Realistic Explosion Mod V.2 www.gta4-mods.com [PUSH] M16 A2 www.gta4-mods.com 2003 Volkswagen Bora V6 www.gta4-mods.com 2013 Ferrari 458 Spider www.gta4-mods.com 2013 SRT Viper GTS www.gta4-mods.com 2012 Porsche Cayenne Turbo *update* www.gta4-mods.com 2010 Bentley Continental SuperSports [EPM] www.gta4-mods.com 2012 Chevrolet Camaro ZL1 www.gta4-mods.com Lincoln Town Car Limousine 2006 (beta) www.gta4-mods.com 1959 Chevrolet Biscayne www.gta4-mods.com GMC <b>...</b>",
    "thumbnail": {
        "sqDefault": "http://i.ytimg.com/vi/rdprvN3g3EU/default.jpg",
        "hqDefault": "http://i.ytimg.com/vi/rdprvN3g3EU/hqdefault.jpg"
    },
    "player": {
        "default": "https://www.youtube.com/watch?v=rdprvN3g3EU&feature=youtube_gdata_player",
        "mobile": "https://m.youtube.com/details?v=rdprvN3g3EU"
    },
    "content": {
        "1": "rtsp://v6.cache8.c.youtube.com/CiILENy73wIaGQlF3ODdvGvarRMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
        "5": "https://www.youtube.com/v/rdprvN3g3EU?version=3&f=videos&app=youtube_gdata",
        "6": "rtsp://v6.cache8.c.youtube.com/CiILENy73wIaGQlF3ODdvGvarRMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp"
    },
    "duration": 615,
    "aspectRatio": "widescreen",
    "rating": 5,
    "likeCount": "8",
    "ratingCount": 8,
    "viewCount": 35,
    "favoriteCount": 0,
    "commentCount": 4,
    "accessControl": {
        "comment": "allowed",
        "commentVote": "allowed",
        "videoRespond": "moderated",
        "rate": "allowed",
        "embed": "allowed",
        "list": "allowed",
        "autoPlay": "allowed",
        "syndicate": "allowed"
    }
}

I get everything I need... With v3 it's looking like I have to make the following requests

https://www.googleapis.com/youtube/v3/search?part=id&key={YOUR_API_KEY}

Which gives me a name and description and channelId

https://www.googleapis.com/youtube/v3/videos?id=rdprvN3g3EU&part=snippet%2C+contentDetails%2C+statistics&key={YOUR_API_KEY}

This guy then gives me the view count

https://www.googleapis.com/youtube/v3/channels?part=snippet&id=rdprvN3g3EU&key={YOUR_API_KEY}

And this final request to get the name of the author...

In v2 I only need to make a single request to get everything I need, and you'd expect the fields that I am requiring to be present in a standard search request anyway surely? I can't see any support for batch requests in v3 either. Am I missing something? Don't even get me started on the implications with rate limiting either :(

Using v3 to perform a simple search I use 3 quota units for the first request, 7 for the second and a further 3 for the final.

13 quota units to perform a single video search per user, displaying what I consider to be relatively standard information.

like image 772
Paul Cooper Avatar asked Feb 11 '13 14:02

Paul Cooper


1 Answers

You can make batch requests by comma separating the video id's in the id= parameter like so:

https://www.googleapis.com/youtube/v3/videos?id=9OBm7aYa6Ic%2C+PTlL2N5Iwh8&part=id%2Csnippet%2Cstatistics&key={YOUR_API_KEY}

I'm not entirely sure how your application works, but you could store the name of the channel so a call for a given channelId only has to happen once.

If you wanted to make the requests smaller, it looks like you aren't using the contentDetails part of your videos call.

like image 154
Matt Koskela Avatar answered Oct 07 '22 11:10

Matt Koskela