Know if I'm streaming using Axios & ReactJS

Hey, I’ve been on the forum searching for my answer for long now, but I need help to connect my website to the New Twitch Api, but I don’t know how to do. Can someone explain me it easily ?

I’m a new developer and the docs seems very complicated for me… Plus, I’m not English so I don’t understand some things in the docs.

I’m using ReactJS and Axios to retrieve data, and I need API to check if I’m streaming or not, and get the Stream’s title, game, watchers, etc…

Thank you !

I’ve already tried this :

componentDidMount() {
    this.getTwitchData()
}

With this :

getTwitchData = () => {
    axios.defaults.headers.common["Client-ID"] = 'xxx';
    axios
      .get("https://api.twitch.tv/helix/streams?user_login=username")
      .then(response => {
        console.log(response.data);

        console.log(response.data.length);
      })
      .catch(error => {
        console.log(error);
      });
  }

And I’m getting 401 error. I understood that I need a token or something but this is it …

So the OAuth token is used, to make sure you have the right access to access this endpoint. In general this shows how the Authentication of the Twitch API works. This shows how to do this for an OAuth token: https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/ Authentication is a rather big topic to summarize, so i think it would be easier that you take a look at the guides first and just hit me up with any specific questions that might come up.

To expand.

here you should be getting your React Server to generate an App Access Token (aka Client Credentials)

Then your front end will call your backend, and the backend performs the API call
Your backend may also then utilise Webhooks for Stream Updates if thats useful and/or caching to negate the need to call the Twitch API at all.

(Why go fetch data if you already fetched it in the last 5/10 minutes (or cache as relevant depending on the endpoint))

Do I need to have a Backend ? My app is Frontend only for now, since I don’t know that much about Backend :sob:

I’ve already looked at the API docs, but everything is confused for me …

if you want to be pure front end, then every user visiting your website, will need to login with Twitch in order to get a token so you can call the API.

It’s look that it’s very hard…

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