Get request header issue

I am currently trying to send a get request to ‘https://api.twitch.tv/helix/streams’, but I am having some issues. I have used the following header described in https://dev.twitch.tv/docs/api/reference#get-streams, but keep getting a response 400 ‘bad request’ sent back.

head = {
‘client-id’:client_id,
‘Authorization Bearer’:token
}

Looking at it again it looks like instead of ‘Authorization Bearer’:token I should have added 'Bearer ’ to the beginning of the token string and just used ‘Authorization’:. I tried this as well, but to no avail. This time, however, I got a status 401 ‘invalid OAuth token’ reply.

I have registered a developer application at https://dev.twitch.tv/console, where I took the client id from and generated a few clients secrets that I have tried using with it, but none of these have worked. I’m not sure if my formatting is incorrect or if my token is bad. I would greatly appreciate any help that anyone has to offer.

should be

head = {
'client-id': client_id,
'Authorization': 'Bearer ' + token
}

thanks for the speedy reply. I tried that as well, but I ran into a slightly different issue of it returning ‘invalid OAuth token’. Is the way in which I got the OAuth token correct?

Make sure it’s BearerSPACEtoken and you can check your tokens validity using the validate endpoint

Any valid token (user or app access) will work for the Streams endpoint

I have the space after ‘Bearer’. I just generated a new token using the https://dev.twitch.tv/console/apps and tried to get request the validate endpoint, but that also returned a status 401 indicating that the access token i just generated is invalid. Is there some reason that the secrets I just generated would be invalid?

You can’t generate a token via the console.

This sounds like you generated a new client secret and you are trying to use your client secret.

You need to use your cleintID and secret to generate a token.

This covers how to generate an App Access Token

I have now tried sending a post request to https://id.twitch.tv/oauth2/token. It told me that I am missing a client secret.

head = {
		'client-id':client_id,
		'client_secret':client_secret,
		'grant_type': 'client_credentials'
}


r = requests.post(API_ENDPOINT,headers = head)

Also there may be a typo in the docs. It says to use client_id in the header, but when i used that it said i was missing a client id. I also tried client-secret in the header, but that did not work.

You don’t send a header to the OAuth client credentials flow endpoint

It’s sent as query string or POST body data

Node JS Example:

Thank you for your patience. For anyone that may need this:

head = {
‘client_id’:client_id,
‘client_secret’:client_secret,
‘grant_type’: ‘client_credentials’
}

r = requests.post(API_ENDPOINT,data = head)

Note: client_id is used here, not client-id as i previously thought.

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