YouTube.search (API) returns empty array

2019-08-08 09:35发布

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)

enter image description here

1条回答
对你真心纯属浪费
2楼-- · 2019-08-08 10:11

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!

查看更多
登录 后发表回答