Need some help with twitch API

I am working with react and axios, i want to get all the live streams from the API

my problem is that i dont know how to convert the curl in the docs to an axios code…
for sure i am doing something worng here… please if someone can help

here is my code

componentDidMount = () => {

 axios({
  url: 'https://api.twitch.tv/kraken/streams/',
  method: 'get',
  headers: 'Client-ID: xxxxxxxxxxxxxxxxxxxxxx'
})

  .then(res => {
    console.log(res)
    console.log(res.data);
  });

}

Since you are calling Kraken, you need the Accept header which is missing.

Having never used Axios I’m fairly sure headers needs to be an object not a string

headers: ‘Client-ID: xxxxxxxxxxxxxxxxxxxxxx’

becomes

headers: {
    ‘Client-ID': 'xxxxxxxxxxxxxxxxxxxxxx’,
    'Accept': 'application/vnd.twitchtv.v5+json'
}

thanks!!! its works!

another problem :
why if i try the get games GET https://api.twitch.tv/helix/games/top
not working on the same code? (just url replace)

parse out the error and read the response

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