Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Youtube data api v3 - how to ask for only a part of snippet in playlists?

When I fetch a list of videos from a playlist with the youtube data api v3 (with youtube.playlists.list), I can define a list of parts to retrieve with the parameter "parts" in order to minimize the data load.

The api states (several places) that asked for a property with child properties, it will include all children properties too. But I can't find anywhere how to restrict a request to a child property, without getting all other parts?

In specific, I am interested in a specific thumbnail, but not in ids, descriptions, titles, other thumbs. So how do I specify a (gran)child property, without getting all parent and sibling properties too?

This is what the request looks like:

gapi.client.request({
    'path': '/youtube/v3/playlistItems',
    'method': 'get',
    'params' : {
        'part' : 'id, snippet.thumbnails.default',
        'maxResults': numberOfItems,
        'playlistId': playlistId,
        'order': 'date'
    }
}).execute(function (jsonResp, rawResp) {
    // do the funky chicken dance
});

I have tried the following:

part : 'snippet.thumbnails.default',

part : 'snippet#thumbnails#default',

part : 'default'

Neither worked out.

But I might be barking up the wrong tree here? Is it too much hassle to break up snippet into parts? Should I just accept to fetch the entire snippet, and dig out the part of interest clientside?

Thanks in advance.

like image 559
hasse Avatar asked May 04 '15 14:05

hasse


People also ask

What is part parameter in YouTube API?

The part parameter is a required parameter for any API request that retrieves or returns a resource. The parameter identifies one or more top-level (non-nested) resource properties that should be included in an API response. For example, a video resource has the following parts: snippet.

What is snippet in YouTube API?

The snippet object contains basic details about the video, such as its title, description, and category. The date and time that the video was published. Note that this time might be different than the time that the video was uploaded.

Is YouTube data API v3 free?

Yes, using the YouTube API does not incur any monetary cost for the entity calling the API. If you go over your quota an 403 Error will be returned by the API.


1 Answers

Use the fields parameter to specify which subset you want from the results:

gapi.client.request({
    'path': '/youtube/v3/playlistItems',
    'method': 'get',
    'params' : {
        'part' : 'id, snippet',
        'maxResults': numberOfItems,
        'playlistId': playlistId,
        'order': 'date',
        'fields': 'items(snippet/thumbnails/default)'
    }
}).execute(function (jsonResp, rawResp) {
    // do the funky chicken dance
});
like image 179
Lorne Laliberte Avatar answered Nov 17 '22 22:11

Lorne Laliberte