First Post - Trouble Authenticating with Nightbot API

I’m trying to write a python script that will pull some data from Nightbot through the API and eventually write that data to a .txt file so I can display it on screen while streaming.

However, I’ve run into problems authenticating with the API. Every time I run the script, I get a 400 error back. I know that my syntax is probably wrong somewhere but I can’t seem to figure out what’s wrong here.

import requests
import json

##Authorization POST Request
# defining the api-endpoint  
API_ENDPOINT = "https://api.nightbot.tv/oauth2/token" 

# your API key here 
CLIENT_ID = "XXX"
CLIENT_SECRET = "YYY"
DATA = {'grant_type':"client_credentials", 'client_id' : 'CLIENT_ID', 'client_secret' : 'CLIENT_SECRET', 'scope': 'commands'}

# sending post request and saving response as response object 
r = requests.post(API_ENDPOINT, data=DATA)
print(r)

Nevermind, I’m an idiot. Obviously you can’t put variable names in quotes and expect them to work.

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