Keep get error 403 forbidden

just cant write in chat. Get bearer_token with
#access_token=&scope=channel%3Abot+user%3Abot+user%3Awrite%3Achat+moderator%3Amanage%3Aannouncements&token_type=bearer

Was able to get follower list with another token and code, but this 2 didn’t work

import requests

client_id = '3gpdymotr4fxjg6jr05eiszf9tz3b5'
bearer_token = ''
broadcaster_id = 861649060

url = 'https://api.twitch.tv/helix/chat/announcements?broadcaster_id=861649060&moderator_id=861649060'

headers = {
    'Authorization' : f'Bearer {bearer_token}',
    'Client-Id'     : f'{client_id}',
    'Content-Type'  : 'application/json'
}
data = {
    'message'   : 'Hello, world! twitchdevHype',
    'color'     : 'purple'
    }

response = requests.get(url, headers=headers, data=data)

if response.status_code == 200:
    response_data = response.json()
    print(f"Message ID: {response_data['data'][0]['message_id']}, Sent: {response_data['data'][0]['is_sent']}")
else:
    print(f"Error: {response.status_code}, {response.text}")

and

import requests

client_id = '3gpdymotr4fxjg6jr05eiszf9tz3b5'
bearer_token = ''
broadcaster_id = 861649060

url = 'https://api.twitch.tv/helix/chat/messages'

headers = {
    'Authorization' : f'Bearer {bearer_token}',
    'Client-Id'     : f'{client_id}',
    'Content-Type'  : 'application/json'
}
data = {
    'broadcaster_id': f'{broadcaster_id}',
    'sender_id'     : f'{broadcaster_id}',
    'message'       : 'Hello, world! twitchdevHype'
    }

response = requests.get(url, headers=headers, data=data)

if response.status_code == 200:
    response_data = response.json()
    print(f"Message ID: {response_data['data'][0]['message_id']}, Sent: {response_data['data'][0]['is_sent']}")
else:
    print(f"Error: {response.status_code}, {response.text}")

Already try to create new token, but 403 :frowning:

What is the body of the response?

The HTTP code is half the information, the body should contain a descriptive error

ERROR: The request could not be satisfied

403 ERROR

The request could not be satisfied.


Bad request. We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.
If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.

Generated by cloudfront (CloudFront)
Request ID: a2_1hT80gOikEGpqugl8BqX8Cl-nI7aZ0p0qo6S0wz5IiO_IUs8M8g==

You’ve tried to send a body with a GET request

Both of these should be POST requests not GET requests

Docs: Reference | Twitch Developers and
Reference | Twitch Developers show the use of the POST verb in the URL and example.

You’ve done a GET request instead

Thanks a lot, I didn’t think that I’m that blind.

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