Authentication in php with oAuth

I’m totally new to APIs in general only have some php experience.

I just basicly need a button to login via twitch and then I can read their username.

This isn’t secure information so there isn’t a token needed.

But as far as I understand correctly, I have to do it anyways to get a token and then get the username.

My problem is twitch spits out

{
"error": "Bad Request",
"status": 400,
"message": "client does not exist"
}

I used this url out of a tutorial

https://api.twitch.tv/kraken/oauth2/authorize?response_type=code&client_id=[clientid]&redirect_uri=[http://localhost:8000/]&scope=[user_read]

clientid is obviously my Application ID that I have censored

And here is the tutorial I was following
https://github.com/justintv/Twitch-API/blob/master/authentication.md#auth-code

Any help would be really cool!

Hey, remove the [] brackets from the URL.

For example:
https://api.twitch.tv/kraken/oauth2/authorize?response_type=code&client_id=clientid&redirect_uri=http://localhost:8000/&scope=user_read

Thanks just a quick 2nd question.

The token appears in the url after you get redirected can I use that token in the URL?

I have it in php with the function $_SERVER['QUERY_STRING']

but the offical API documentation says I need to use

POST https://api.twitch.tv/kraken/oauth2/token

But I don’t know how to use this “post”

You will need to make the POST request as specified in the Authentication doc. For background you can read about POST here: http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html . Essentially it is the method data is sent from forms on websites to the server.

I did a quick google search for sending a POST request from PHP and found: https://stackoverflow.com/questions/5647461/how-do-i-send-a-post-request-with-php

If you are using a framework, I would suggest looking into a more specific way to do it from within that framework as it may be cleaner and in better practice.

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