Your code broadly looks correct
You do not need
"redirect_uri": encodeURIComponent(redirect),
"response_type": "token",
on your token generator. See Getting OAuth Access Tokens | Twitch Developers
You also call the varable in your code header but it’s post data (not a issue just a confusing name)
It’s just client_id/client_secret/grant_type
But if you are getting a token then all good.
So it would seem that whatever UrlFetchApp.fetch is is messing about and not doing what we think it’s doing.
So your code seems ok, but if it’s getting a 404 on the second call (and not the first with the token gen). then seems there might be a library issue