Why am i still unauthorized? HTTP Twitch 2AuthO request in Lua with coro-http

68 Views Asked by At

I am 100% sure that my client-id and client-secret are valid. I used it in my python code and it just worked fine

local http = require("coro-http")
local json = require("json")

local url = "https://id.twitch.tv/oauth2/token"

local client_id = "<>"
local client_secret = "<>"

local headers = {
["Content-Type"] = "application/x-www-form-urlencoded"
}

local body = "client_id=" .. client_id .. "&client_secret=" .. client_secret .. "&grant_type=client_credentials"

local response, w = http.request("POST", url, headers, body)
print(w)

local data = json.decode(w)
local access_token = data.access_token

local headers = {
["Client-ID"] = client_id,
["Authorization"] = "Bearer " .. access_token 
}

local response, b = http.request("GET", "https://api.twitch.tv/helix/channels?broadcaster_id=141981764", headers)
  print(b)

Getting token and then do a simple get request

1

There are 1 best solutions below

0
tteixeira On

I found this repository which is doing exactly what you're trying to.

From the code you provided and the one from the above repo, I would say @LMD comment is the way to go. You need to urlencode your body string.
Maybe querystring from luvit could be a good starting point.