Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
Youtube API loop stops

I'm very new to programming. I'm trying to make a project where a locally hosted website, would fetch titles of the songs from a youtube playlist and then adds them to a list. So far, it fetches the first 50 items/titles, but then the loop stops. What goes wrong here?

let tracks = [];
let token = "";
let items;
let items_total;

function execute() {
        do {
        return gapi.client.youtube.playlistItems.list({
            "part": ["snippet"],
            "maxResults": 50,
            "pageToken": token,
            "playlistId": "id of the playlist"
        }).then(function(response) {
            let playlist = response;

            items = playlist.result.pageInfo.resultsPerPage;
            items_total = playlist.result.pageInfo.totalResults;
            token = playlist.result.nextPageToken;

            for (let i = 0; i < items; i++) {tracks.push(playlist.result.items[i].snippet.title)}
        },
        function(err) { console.error("Execute error", err); });
    } while (tracks.length < items_total)
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!