import requests
from urllib.parse import urlencode
client_id = '***'
client_secret = '***'
# auth
data = {
'client_id': client_id,
'client_secret': client_secret,
'grant_type': 'client_credentials',
'scope': 'channel:manage:broadcast'
}
response = requests.post('https://id.twitch.tv/oauth2/token', data=data).json()
print(response)
token = response['access_token']
headers = {
'Client-Id': client_id,
'Authorization': 'Bearer ' + token,
}
# get broadcaster id
data = {
'login': ['Flexlolo']
}
url = 'https://api.twitch.tv/helix/users?' + urlencode(data, doseq=True)
response = requests.get(url, headers=headers).json()
print(response)
broadcaster_id = response['data'][0]
# change title
data = {
'broadcaster_id': broadcaster_id,
'title': 'NEW TITLE STRING'
}
url = 'https://api.twitch.tv/helix/channels?' + urlencode(data, doseq=True)
response = requests.patch(url, headers=headers).json()
print(response)
and the output looks like this:
{'access_token': '***', 'expires_in': 4712212, 'scope': ['channel:manage:broadcast'], 'token_type': 'bearer'}
{'data': [{'id': '89346924', 'login': 'flexlolo', 'display_name': 'Flexlolo', 'type': '', 'broadcaster_type': '', 'description': '', 'profile_image_url': 'https://static-cdn.jtvnw.net/jtv_user_pictures/77a99df0-48fc-4764-8d0b-29f6da6df736-profile_image-300x300.png', 'offline_image_url': '', 'view_count': 4972, 'created_at': '2015-04-24T07:05:45.847672Z'}]}
{'error': 'Unauthorized', 'status': 401, 'message': 'incorrect user authorization'}