Stream data empty

hello,
my project is to create a chrome extention who make a notification when a streamer is on live.
so i have a script who check every 10sc if it’s the case :

check(); setInterval(function () {check(); }, 10000);

async function check() {

 let storage = await getStorageData();

 const streamData = await getStreamData();
 if (streamData && streamData.type === 'live') {
     chrome.browserAction.setIcon({path: config.images.icon_on_64});
     if (storage.notifications && !await streamIsOpen()) {
         if (storage.notified || (new Date()) - storage.notified > 60 * 60 * 1000) {
             if (config.notification.message === '') config.notification.message = streamData.title;
             chrome.notifications.create(config.notification);
             chrome.storage.local.set({notified: new Date()});
         }
     }
 } else {
     chrome.browserAction.setIcon({path: config.images.icon_off_64});
     chrome.storage.local.set({sent: null});
 }}

this one have 2 objectif : find if the live is on and if it’s on change the icon of the extention
but the return of the streamData is empty .

for this i use some functions :

async function OAuth() {
return await new Promise(resolve => {
    $.ajax({
        type: 'POST',
        url: `https://id.twitch.tv/oauth2/token?client_id=${config.client_id}&client_secret=${config.client_secret}&grant_type=client_credentials`,
        success: res => resolve(res || null),
        error: err => resolve(null),
    })
});}

this one for Oauth who take some info on a config.js
and , normaly, create an acces_token

and my getstreamdata function

async function getStreamData() {

return await new Promise(resolve => {
    $.ajax({
        dataType: 'json',
        headers: {'Client-ID': config.client_id, 'Authorization': 'Bearer ' + config.access_token},
        url: "https://api.twitch.tv/helix/streams?user_login=" + config.channel_name,
        success: stream =>
            stream && stream.data && stream.data[0]
                ? resolve(stream.data[0])
                : resolve(null),
         error: err => resolve(null),
    });
});}

it’s my first time on APi and JS and don’t know how to solve it.

sorry for my realy bad english and ty for the future help :slight_smile:

If you’re making an browser extension, you shouldn’t be using the Client Credentials OAuth flow as that exposes your client secret to anyone using the extension. You should either use a backend server, or require the user of the extension go through the implicit auth flow.

The API uses caching, you shouldn’t request the same data more than once every minute.

What do you mean it’s ‘empty’? Your getStreamData is a little hard to read but appears to be sending either null (for an offline stream), or if the stream is live it should return the stream object, so I’m not sure what you mean by ‘empty’.

ok i change this now

exactly it null every time , and if live is online , it’s null too and it’s my pb

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.