Hi, I have a bot written in Python and would like to use that to edit my own stream title (my stream name differs from that of the bot). From what I gather I need to register an app to get a client ID & secret (using my actual stream name, not that of the bot), make a POST request to get an app access token with channel_editor scope (not sure if openid is needed as well) and then use this to make a PUT request to edit my channel stream title. So far I’ve been able to get the access token with the following code:
I get a 401 response - ‘invalid oauth token’ and am unsure how to fix it. Hopefully it’s something simple - I’ve read something about that the access token isn’t the same as an oauth token but I have no idea what other code I could possibly use.
I’m getting 400 ‘no client id specified’. If I copy and paste the GET request (putting in client id, redirect uri, response type and scope) into a web browser I get taken to localhost with a code and channel_editor scope though.
Edit: noticed I had to use params instead of headers in the get request. Removing the .json() from the end of getResponse gives me code 200 which I think is good?
Okay thanks. The above code (with .url) gives me the link to log in -> authorization -> access code. For the time being I can’t make my bot automatically log in (error message is similar to ‘Forbidden - missing csrf token’); I need to find the right csrf token and post it in the login form. I assume when getting this part right I can automatically grab the oauth token without needing to manually open a webpage.
You should NOT I repeat NOT be logging into Twitch this way.
You should write code that allows you to auth your application to your Twitch (Bot) Account. Which provides an access token. Then you use the access token with the bot. The bot itself should NOT be logging into Twitch itself. IE two separate programs.
The bot should never have code to go and login to Twitch on it’s own.
You only need to do this step once ever… Unless you de-auth your application from the Twitch Account.
Thats not a “workaround” thats how you are supposed to do it.
People used to use and may still use a service like https://twitchapps.com/tmi/ to generate an oAuth token for them, then the bot only needs that token, and the ability to refresh said token (which you won’t be able to do with the TMI generator), now that tokens expire. (ClientID’s made before a certain point in time don’t require refresh).
Yes but you are given a refresh token to use to get a new token (and an expires in time)
In summary, your bot only needs the code to refresh a token, it does NOT need the code to generate the token.