admin管理员组

文章数量:1335877

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.

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.

Share Improve this question asked May 4, 2015 at 14:23 hassehasse 9032 gold badges11 silver badges24 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

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
});

本文标签: javascriptYoutube data api v3how to ask for only a part of snippet in playlistsStack Overflow