Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

121
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda