1

I don't know how to combine them. I made a code by referring to the link below. Please Help me...

Android - Checking if a twitch stream is online

Is There Any Way To Check if a Twitch Stream Is Live Using Python?

setting

export const CHANNEL_NAME = ["daXXXXXX", "gmXXXXXXX"];
export const OAUTH_TOKEN = 'oauth:bn1rXXXXXXXXXXXXXXXXX';
export const CLIENT_ID = 'bxqtXXXXXXXXXXXXXXXXX';
export const BOT_USERNAME = 'gaXXXXt';

my code

async function test2() {
    var theUrl = `https://api.twitch.tv/kraken/streams/${CHANNEL_NAME[0]}`
    var headers = {
        "Client-ID": CLIENT_ID

    };
    fetch(theUrl, headers).then(data =>{
        console.log(data)
    })
  }
test2()

debug data

Response {
  size: 0,
  timeout: 0,
  [Symbol(Body internals)]: {
    body: PassThrough {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 5,
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: true,
      [Symbol(kCapture)]: false,
      [Symbol(kCallback)]: null
    },
    disturbed: false,
    error: null
  },
  [Symbol(Response internals)]: {
    url: 'https://api.twitch.tv/kraken/streams/#daXXXXXX',
    status: 400,
    statusText: 'Bad Request',
    headers: Headers { [Symbol(map)]: [Object: null prototype] },
    counter: 0
  }
}
VLAZ
  • 26,331
  • 9
  • 49
  • 67
gagore
  • 15
  • 4
  • Kraken has been deprecated, Try with [Helix](https://stackoverflow.com/a/66536359/1456151) or [GraphQL](https://stackoverflow.com/a/71289342/1456151). Do you need to use the API or just to check if user is online? You can [fetch the whole page](https://stackoverflow.com/a/67969583/1456151) then check if contains text `isLiveBroadcast` – Doger Jun 14 '22 at 18:15

1 Answers1

4

The twitch kraken has been decommissioned, you need to use the helix api instead.

async function isStreamerLive(username) {
    const theUrl = `https://api.twitch.tv/helix/streams?user_login=${username}`
    const headers = {
        "Client-Id": CLIENT_ID,
        "Authorization": OAUTH_TOKEN
    };

    const response = await fetch(theUrl, headers);
    const data = await response.json();

    return data?.data?.find(s => s.user_login === username.toLocaleLowerCase())
  }
Zusor
  • 88
  • 6