YouTube.search (API) 返回空数组 [英] YouTube.search (API) returns empty array

查看:21
本文介绍了YouTube.search (API) 返回空数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中,我使用 promise 来控制异步,在下一个请求中我发送 nextPageToken,但随后发送带有空视频的请求

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

--- 代码 -

  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
  });
}

--- 代码 -

第9次后的答案是空的排列(物品)

The answer after the 9th time is an empty arrangement (items)

推荐答案

我有类似 Youtube 搜索方法的情况,我可以推荐使用 publishedAfterpublishedBefore 参数来缩短搜索时间.看起来 Youtube 试图通过估计来优化每个搜索请求的 CPU 服务器时间.因此,您需要更具体地使用您的搜索查询,或者您需要缩短搜索的时间范围.例如,我尝试了非常具体的视频,在描述中具有唯一编号.我可以在 Youtube 网站上轻松找到它,但如果不添加 publishedBeforepublishedAfter 大约 1 小时的发布时间,我无法使用 search 方法.所以,试试吧!

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!

这篇关于YouTube.search (API) 返回空数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆