What am I missing?
(I’m trying to do this to get the OAuth token and then use that to get to api.twitch.tv/helix/streams to poll my channel. If there’s a better way to do this, I’m all ears.)
<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
</body>
</html>
That’s what I get back in the serial monitor on the chip. Here’s the code to get that:
while (client.connected()) {
String line = client.readStringUntil(’\n’);
if (line == “\r”) {
Serial.println(“headers received”);
break;
} else {
Serial.println(String("Headers: ") + line);
}
}
Serial.println(“reply was:”);
Serial.println("==========");
String line;
while(client.available()){
line = client.readStringUntil(’\n’); //Read Line by Line
Serial.println(line); //Print response
}
Serial.println("==========");
Serial.println(“closing connection”);
Those all show up with the “Headers” tag in the Serial monitor, so they’re being processed in the inital “headers” section there. From what I can tell, I’m not getting any other information back from the server. (Or I’m missing the code needed to catch it.)
Got it. So here’s my POST command in the code:
client.print(String(“POST “) + OAUTHURL + “?client_id=” + CLIENTID + “&client_secret=” + CLIENTSECRET +”&grant_type=client_credentials\r\n” +
“Content-Type: application/json” +
“Accept: application/json”);
Have I messed something up there? Or missed something? Or should the string I send the https connection read more:
curl -X POST …
with some -H lines as well?
Changed the methods I was using to POST to the server and I’m getting helpful error messages now. (Down to “missing client secret” which I’m sure is just missing the formatting I need to get it to recognize it.)