1

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

3
  • What's your expected outcome? Is it supposed to show more results or could it be that there's nothing more to show? Commented Mar 18, 2018 at 11:41
  • I've noticed YouTube does seem to return empty items when there are no more results. Check for that condition. Commented Mar 18, 2018 at 15:33
  • I expect more results, because in the first result returns {pageInfo: resultsPerPage: 50,totalResults: 1000000}, and I'm barely in the 350 Commented Mar 18, 2018 at 15:38

1 Answer 1

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.