Help connecting a Twitch account to my own streaming deck

Hello guys, I’m making my own streaming deck. There will be features such as switching the chat to follower mode only via buttons, but there is something I’m stuck on: the user will come and enter their information, the user password and account will remain registered, how can I do it?

I am writing in Python, I have python knowledge, but my API knowledge is a little weak. The user will click on connecting his account, the browser will open, then he will enter the information. After entering, his account will remain registered and he will receive the necessary tokens. How can I do this?

Which tokens are needed to perform the necessary control operations.

I would be very grateful if you could help me, thank you very much in advance.

You need a User oAuth token.

For your use case likely DCF is the most effective flow - Getting OAuth Access Tokens | Twitch Developers

Hello, thanks for your reply. I didn’t understand it very well, looking at the stream decks on the market from the documentation, I didn’t understand that only the user pass is enough, there is no need to authorize anything.

as an example, I found the code to make the chat only followers special mode from the api, but I get the tokens and after a certain period of time it becomes ineffective.

Tokens don’t last for ever

User tokens (generally) live for four hours

The valiate token endpoint will tell you how long a token has left Validating Tokens | Twitch Developers

Ignore them as they don’t help you as the magic source that makes authentication go is different to what you are going to achieve and thus it’s bogging you down needlessly.

But basically

  • Elgato Stream deck → create an elgato account
  • Using the Elgato account pair it with a Twitch account via code flow oAuth
  • Now the stream deck can ask the Elgato server via the elgato account to return the current Twitch oAuth token and refresh if needed on the Elgato server

this predates DCF existing, so an external accounts system makes sense, even more so with Elgato market place.

For you, you want DCF so most of the Documentation around existing Decks will not help you. Since they cover how to use the deck/build plugins and not how to authenticate to other services…

import requests

url = 'https://api.twitch.tv/helix/chat/settings'
headers = {
    'Authorization': 'Bearer Token',
    'Client-Id': 'CLİENT İD',
    'Content-Type': 'application/json'
}
params = {
    'broadcaster_id': '223285784',
    'moderator_id': '223285784'
}
data = {
    #'follower_mode': True,
    "subscriber_mode": False
}

response = requests.patch(url, headers=headers, params=params, json=data)

print(response.status_code)
print(response.json())

I want to get the tokens in this code, but the user will not enter them manually, he needs to link his account as in the picture, I wonder how to do this, for some reason I can’t find it, when I say link, the browser will open.

authorization-dialog

Assuming usign DCF Getting OAuth Access Tokens | Twitch Developers

You would

  • do the first dcf step
  • Which gives you a URL
  • Present the URL to the user to click or open the default browser

How to do that depends on the specifics of the frameworks or UI or window system/etc you are or are not using.

These steps are outlined in twitch_misc/authentication/electron_devicecode at main · BarryCarlyon/twitch_misc · GitHub

import requests
import json

url = 'https://id.twitch.tv/oauth2/device'
client_id = 'kimne78kx3ncx6brgo4mv6wki5h1ko'
scopes = 'moderator:read:chat_settings'

data = {
    'client_id': client_id,
    'scopes': scopes
}

response = requests.post(url, data=data)

print(response.text)

response_data = json.loads(response.text)
device_code = response_data["device_code"]

while True:
    url = 'https://id.twitch.tv/oauth2/token'
    grant_type = 'urn:ietf:params:oauth:grant-type:device_code'

    data = {
        'client_id': client_id,
        'scopes': scopes,
        'device_code': device_code,
        'grant_type': grant_type
    }

    response = requests.post(url, data=data)

    if response.status_code == 200:
        print("Başarılı")
        response_data = json.loads(response.text)
        access_token = response_data["access_token"]
        break
    else:
        print("hata")
        
    

url = 'https://api.twitch.tv/helix/chat/settings'
headers = {
    'Authorization': f'Bearer {access_token}',
    'Client-Id': 'kimne78kx3ncx6brgo4mv6wki5h1ko',
    'Content-Type': 'application/json'
}
params = {
    'broadcaster_id': '1069820836',
    'moderator_id': '1069820836'
}
data = {
    'follower_mode': True
    #"subscriber_mode": False
}

response = requests.patch(url, headers=headers, params=params, json=data)

print(response.status_code)
print(response.json())

I did it, I get the token but when I try to put the chat in followers mode {‘error’: ‘Unauthorized’, ‘status’: 401, ‘message’: ‘Missing scope: moderator:manage:chat_settings’} I get this error scope is correct but

This isn’t your clientID. So you won’t be able to do refreshes

You need to use your own.

You only asked for read. And you need read and manage scopes

client id I wonder where to buy it :slight_smile:

and what’s the right way to do it?

You don’t “buy them”

You can obtain your own from Twitch Developers

See also the Getting Started Guide

Scopes are space seperated with encodes to a +

So

scopes = 'moderator:read:chat_settings+moderator:manage:chat_settings'

or

scopes = 'moderator:read:chat_settings moderator:manage:chat_settings'

Not sure how Python will process

hey hello thank you very much, thanks to your help I learned what I wanted.

I don’t know if you can help me with this, but I would be very grateful if you could help me. all I need to do now is to control obs, I want to do it on python, I want to do it on python, I want to open and close the recording, scene transitions, etc. There is an api documentation of this, but I didn’t understand it much, and it was written in c. I wonder if I can do it with python, I couldn’t find an example.

documentation : OBS Studio Frontend API — OBS Studio 30.1.2 documentation

I would be very grateful if you could help me with this issue.

Kinda off topic to this forums.

However I would look at OBS websockets

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