0

I am expecting for the functionality using NestJS to make API call, and in case if I get token for next call then I need to make a request to the same API with that token as query params. The limitation is API returns only 50 records without token so to get next records I need to attach query params. In case if the token is empty I need to end the call. Fetching videos from youtube against particular uploaderId.

Sample I have written.

getPlaylistVideos(playlistId: string): any {
    this.videos = [];
    return new Promise((resolve, reject) =>
        this.http
            .get(this.getPlaylistURL(playlistId, ''))
            .pipe(
                map(response => response.data),
                tap(() => console.log('\t', `Getting details by URL: this.http.get(this.getPlaylistURL(${playlistId})`)),
                tap(videoResponse => {
                    this.videos.push(...videoResponse.items);
                    if (videoResponse['nextPageToken']) {
                        console.log('\t', 'NextToken: ', videoResponse['nextPageToken']);
                        return mergeMap(video => {
                            console.log('\t', `this.http.get(this.getPlaylistURL(${playlistId}, ${video['nextPageToken']})`);
                            return this.http.get(this.getPlaylistURL(playlistId, video['nextPageToken']));
                        });
                    } else {
                        console.log(`videoResponse:`, videoResponse['nextPageToken']);
                        return empty();
                    }
                })
            )
            .toPromise()
            .then(response => resolve(this.videos))
            .catch(err => reject(err))
    );
}

It fails to fetch next set of records.

Sankalp
  • 1,300
  • 5
  • 28
  • 52
  • 1
    I am really confused on what are you trying to ask? Are there two APIs? One for fetching the query param and one for getting the records? – emkay May 31 '19 at 05:37
  • Use [`expand`](https://rxjs-dev.firebaseapp.com/api/operators/expand) for recursive pagination. See https://stackoverflow.com/a/54478907/9423231 – frido Aug 13 '19 at 16:12
  • @emkay: Does I mention 2urls. Single function getPlaylisturl generates url for get request with passing second Param as token. – Sankalp Oct 08 '19 at 14:58

0 Answers0