YouTube.search (API) returns empty array

非 Y 不嫁゛ 提交于 2019-12-11 06:35: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)


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!