Authenticating a discord bot with Twitch API

Hi, I’m trying to learn how to use the Twitch API and integrate it into my discord bot project but I’m having issues with authentication. I’ve tried using the ‘OAuth Client Credentials Flow’ as I thought it was the most appropriate for my app, now I’m not so sure. I can’t see the other options being any use as I don’t want to login a user.

I’m writing the bot in node, and sent a request using the URL example:
https://api.twitch.tv/kraken/oauth2/token?’ +
‘client_id=’ + clientId +
‘&client_secret=’ + clientSecret +
‘&grant_type=client_credentials’

This simply returns: {“error”:“Not Found”,“status”:404,“message”:null}

I am starting to think that the Twitch API is not what I should be using to get data from twitch for a discord bot but can’t find an alternative.

Any help is very much appreciated.

EDIT: Problem solved I wasn’t adding the client ID to the header

What information do you need from Twitch for your discord bot? A lot of the data does not require authentication.

For the moment just when a stream is live. But I’ll probably want to get follows and subs too at some point down the line.

I didn’t realize there are parts of the API that don’t require authentication. At first I thought there were but then when I tried to perform API calls I kept getting rejected.

Could it be something along the lines of me not having a web server at the url that the app has set? If this is the case is there a way to use the API without that? Most API’s I’ve used just respond with a json response and are a dodle, I can usually visit them just in my web browser.

Did you include a ClientID in the header?

What was the result code?

What was the URL you were trying?

For non oAuth apps https://localhost/ is fine.

Subscribers will require the relevant permissions from the caster.

OK, so. I don’t know how many times I read the API docs but I clearly didn’t read it well enough because up until you said that I didn’t realize the client ID went into the header. I thought it was a request argument. I’ll now go and work out how to add stuff to the header in node and if it doesn’t work I’ll come back and answer the rest of your questions.

Thanks :slight_smile:

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