问题
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)
回答1:
I have similar situation with Youtube search method and I can recommend to use publishedAfter
and publishedBefore
parameters to reduce timeframe for your search. Looks like Youtube trying to optimize cpu server time for every search request with estimates. So, you need to be more specific with your search query or you need to reduce timeframe for your search. For example I've experimented with very specific video with unique number in description. I can find it on Youtube website easily but I can't with search
method without adding publishedBefore
and publishedAfter
about 1 hour of published time. So, try it!
来源:https://stackoverflow.com/questions/49344550/youtube-search-api-returns-empty-array