In my code I use promises to control the asynchrony, in the next request I send the nextPageToken, but then send the request with empty videos
--- CODE -
search_this_q="cats";
function load(){
search(search_this_q)
.then(function(data){
console.log(data)
return next_Page_Search(data.nextPageToken,search_this_q);
})
.then(function(data){
console.log(data)
return next_Page_Search(data.nextPageToken,search_this_q);
})
.then(function(data){
console.log(data)
return next_Page_Search(data.nextPageToken,search_this_q);
})
.then(function(data){
console.log(data)
return next_Page_Search(data.nextPageToken,search_this_q);
})
.then(function(data){
console.log(data)
return next_Page_Search(data.nextPageToken,search_this_q);
})
.then(function(data){
console.log(data)
return next_Page_Search(data.nextPageToken,search_this_q);
})
.then(function(data){
console.log(data)
return next_Page_Search(data.nextPageToken,search_this_q);
})
.then(function(data){
console.log(data)
return next_Page_Search(data.nextPageToken,search_this_q);
})
.then(function (result) {
console.log(".theen finish load")
console.log(result);
console.log(".theen finish load")
});
}
function next_Page_Search (token_Page,search_this) {
return new Promise((resolve, reject) => {
var data={
part: 'id', //'id,snippet',
maxResults: 50,
pageToken:token_Page,
q:search_this,
type:'video',
// videoEmbeddable:true,
key:"mykey"
};
// GET
$.get("https://www.googleapis.com/youtube/v3/search",
data,function (data,status){
resolve(data);
}
);
// end GET
});
}
--- CODE -
The answer after the 9th time is an empty arrangement (items)