Skip to content

_getComments limit #5

@borodadada

Description

@borodadada

i added limit on load comments

    _getComments(videoId, allComments, nextPageToken = null, limit = 10) {
        const params = {
            key: this._key,
            part: 'snippet,replies',
            videoId: videoId,
            maxResults: 10,
            pageToken: nextPageToken
        };

        const restUri = uri(this._baseuri)
            .filename('commentThreads')
            .query(params);

        return this._doRequest(restUri)
            .then(function(result) {
                if (result && result.items && result.items.length > 0 && allComments.length < limit ) {
                    for (const item of result.items) {
                        if( allComments.length < limit ){
                            allComments.push( item )
                        }else
                            return allComments
                    }
                }

                if( result.nextPageToken ) {
                    return this._getComments(videoId, allComments, result.nextPageToken);
                }
                else {
                    return allComments;
                }
            }.bind(this));
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions