I am trying to request the messages of a live-stream chat via Youtube Data API V3. The problem is that it didn't find the page token. I get following error:
{"error": {"code": 400,"message": "page token is not valid.","errors": [{"message": "page token is not valid.","domain": "youtube.liveChat","reason": "pageTokenInvalid" }] }}This is my JS:
gapi.load('client', start);function start() { fetch('config.json') .then(response => response.json()) .then(config => { gapi.client.init({ apiKey: config.apiKey, discoveryDocs: ["https://www.googleapis.com/discovery/v1/apis/youtube/v3/rest"] }).then(function() { var liveChatId = config.liveChatId; function getChatMessages(pageToken) { gapi.client.youtube.liveChatMessages.list({ liveChatId: liveChatId, part: 'snippet', pageToken: pageToken }).then(function(response) { var chatDiv = document.getElementById('chat'); response.result.items.forEach(function(item) { var message = item.snippet.displayMessage; var messageElement = document.createElement('div'); messageElement.className = 'chat-message'; messageElement.textContent = message; chatDiv.appendChild(messageElement); setTimeout(function() { messageElement.style.transform = 'translateX(100%)'; setTimeout(function() { chatDiv.removeChild(messageElement); }, 500); }, 10000); }); if (response.result.nextPageToken) { getChatMessages(response.result.nextPageToken); } }); } getChatMessages(); }); }).catch(error => { console.error('Fehler beim Laden der Konfigurationsdatei: '+ error); });}