Apologies if this has been answered elsewhere, i tried searching but couldn't find it.
I've written a script (with the help of AI) to display current track info for an overlay.
The issue i'm having is it works perfectly for 5 minutes and then console explodes with error about token not being valid and for the life of me i'm unable to get the script to automate this process using the grant flow (not implicit)
Here is an example of the script that deals with that side of things and hopefully someone infinitely smarter than i can see where i'm going wrong...
javascriptasync function refreshAccessToken(url, params, isNightbot = false) {if (isNightbot && isNightbotRefreshing) {console.log("Nightbot refresh already in progress, skipping.");return false;}if (isNightbot) isNightbotRefreshing = true;try {console.log(`Attempting to refresh ${isNightbot ? 'Nightbot' : 'Twitch'} token...`);if (isNightbot) {console.log("Nightbot refreshToken:", nightbotConfig.refreshToken); // Added logging}const response = await fetch(url, {method: 'POST',headers: { 'Content-Type': 'application/x-www-form-urlencoded' },body: new URLSearchParams(params)});if (!response.ok) {const errorData = await response.text();console.error(`Token refresh failed with status: ${response.status}`, errorData);return false;}const data = await response.json();if (data.access_token) {if (isNightbot) {nightbotConfig.accessToken = data.access_token;if (data.refresh_token) {nightbotConfig.refreshToken = data.refresh_token;