Hi , I am creating a a Discord Bot thats display in a message the number of subs of the channel.
Im trying to get the OAuth authorization code flow token for making a request to get the subs but I dont know how to make it.
I made a GET request (to https://id.twitch.tv/oauth2/authorize) and I get an url , I paste it in google and it goes to a page to autorize the twitch app (all sounds good at this point) but then nothing happens.
It gets me to localhost.
When registrating my app I put http://localhost as the URL and I think thats the error but I dont know.
I have read the documentation a LOT of times but I didnt got a lot of it.
The bot its just for one channel (if this information is important)
Sorry for my bad english.
To obtain a token to access Twitch prividged data.
- You need to create a webpage.
- That webpage will display a
<a href="" that starts
- user clicks that link
- user accepts of denies the link
- if they accept they come back to your return URL with a
?code= you exchange that
?code= for an access token and refresh token via a HTTP POST request.
- You store the user access token and refresh tokens
- Use the user access token till it expires, then make a new token using the refresh token.
- You may get a new refresh token when doing so.
If the refresh token doesn’t work then you’ll need the use you want to read subs for to do this flow all over again.
If you left it as
localhost then sounds like you are authing yourself, then you just need a webserver at that URL to do the auth process.
The above is for “regular” oAuth
You can instead use implict but then every 60 days you have to do the manual steps all over again. (Also generally thats what the third party third party token gens use which makes it annoying to seed it with a new token perodically.
Here are two example projects
One in node and one in PHP that demonstrate this flow. You would need to modify it to store the token/refresh token whever you need to for the discord bot to access it
Ohh you help al lot thanks. But the bot is just for a friend , can’t I just sent the url to authorize the app?
And then I don’t know how to get the token if I just send it him via any chat.
You need a “server” to do the final step for key exchange.
And you may need to periodically get a new key.
Sure but first you need to build the website that does the authentication loop.
And there inst any other way to take the subs of a channel in a simple way?
Or whats the simpliets way to do it??
This is the simplest way to obtain a token from a user that is not you.
You need a website to collect tokens.
Oh ok, the problem is that I dont even know were to start. Any help?
Some Video or forum or documentation or something?
btw thanks barry for the ULTRA quick response my god
Here is a link to the documentation, and two examples in two different langages.
This forum is the forum, and we can answer questions like we already have been doing.
For the TwitchDev Disorc there is this Intro Video about oAuth that might help
Thanks this help me a lot , but I’m very noob with web pages. I imagine I have to create it , paid for hosting and all that thing just for a token??
This is one of the industry standard of obtaining delegated access to someones account.
You can use things like ngrok to reverse proxy a tunnel and use your home machine to handle the hosting.
But your discord bot should be running on hosting so it has reliability. So the same bot hosting can run the web page
Im searching about ngrok and I think is just for local hosting, is this going to work??
ngrok creates a temproary URL that routss to somewhere else. Which could be a localhost.
And if I create the website and host it with ngrok it should work??
Or Is there any way to get subs with any other token of something?
No this is the only way you require a web flow
Ok I dont know how I made a simple webpage, but I dont know what have to be the structure of the page.
I mean I have a button that runs the script that you put on git, I suposed that I have to add my web url to the app in the registrarion page in twitch.
The main question is like ok I ahve the URL that the twitch server provides with the requests , and my web page mid finish, how do I make the interaction betewn them
Thats up to you to determine and solve.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.