我期望使用NestJS进行API调用的功能,并且如果我获得下次调用的令牌,那么我需要使用该令牌作为查询参数向同一API发出请求。限制是API仅返回50条没有令牌的记录,因此要获取下一条记录,我需要附加查询参数。如果令牌为空,我需要结束通话。根据特定的uploaderId从youtube获取视频。
我写的样本。
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))
);
}
它无法获取下一组记录。