Gsx
Gsx

Reputation: 942

Youtube API V3 - Missing items in playlist when requesting them with playlistItems.list

I have been trying to get all the items in this playlist, which has 64 items in it, with javascript.

This is the function i have been using get the response and display the items in the response:

function getPlaylistItems( playlistId, maxResults, pageToken ) {

    var requestOptions = {
        playlistId: playlistId,
        part: 'snippet',
        maxResults: maxResults,
        fields: "items,nextPageToken"
    };

    if ( pageToken ) {
        requestOptions.pageToken = pageToken;
    }

    var request = gapi.client.youtube.playlistItems.list( requestOptions );
    request.execute( function( response ) {

        var playlistItems = response.items;

        console.log( playlistItems.length, playlistItems );
        $.each( playlistItems, function( index, item ) {
            displayResult( item.snippet.title );
        } );

        if ( response.nextPageToken ) {
            console.log( response.nextPageToken );
            getPlaylistItems( playlistId, maxResults, response.nextPageToken );
        }
    } );
    displayResult( "---" );
}

If maxResults = 25 then the first iteration returns videos 01-25, which is what you expect.

But the second iteration goes from 31-55. The third one has no items in it. So I am missing 26-30 and 56-64.

With maxResults = 10 I am missing 31-40. 
With maxResults = 20 I am missing 41-60.
With maxResults = 30 I am missing 31-40. 

(This is not code ^^ Stackoverflow didn't allow me to post otherwise :S )

Is there something I am doing wrong or am I just not getting the correct nextPageToken?

Edit: It is fixed now.

Upvotes: 2

Views: 945

Answers (1)

Als
Als

Reputation: 1415

I think it's a bug. When I retrieve your playlist (PLSJnFrNoXjX_HlX3JA4NGgxmym1Pj26RB), using api version 3, I only get the first page of 50 items.

See also: Retrieve youtube playlist wrong when playlist items count over 100

Update: See also bug report: https://code.google.com/p/gdata-issues/issues/detail?id=6162&q=label%3AAPI-YouTube&colspec=API%20ID%20Type%20Status%20Priority%20Stars%20Summary

Upvotes: 1

Related Questions