Hello !
I’m coding a Twitch library on Gamemaker Studio 2 to listen to events from a channel. So far so good, it works flawlessly through subscription servers and Twitch websocket. On the other hand, with the test server by CLI, in response to my subscription requests I take a:
{"response_headers":10.0,"http_status":400.0,"url":"http:\/\/127.0.0.1:8080\/eventsub\/subscriptions","id":9.0,"status":0.0,"result":"{\"error\":\"Bad Request\",\"message\":\"error validating json\",\"status\":400}"}
I checked my code several times, the JSON is good. Maybe a problem in headers? I’ll give you my GML code if it helps:
function __twitch_sub_to_events(){
__twitch_message("Subscribe to all events...");
global.twitch_state = TWITCH_STATE.SUBSCRIPTION_EVENT_PENDING;
var _events = twitch_get_sub_event();
var _nb_event_to_sub = array_length(global.twitch_user_sub_events);
var _url = global.debug_test ? global.twitch_url_subscribtions_debug : global.twitch_url_subscribtions;
for (var _i = 0; _i < _nb_event_to_sub; _i++) {
var _event = _events[$ global.twitch_user_sub_events[_i]];
var _headers = ds_map_create();
ds_map_add(_headers, "Authorization", __capitalize(global.twitch_token_type) + " " + string(global.twitch_access_token));
ds_map_add(_headers, "Client-Id", string(global.twitch_client_id));
ds_map_add(_headers, "Content-Type", "application/json");
var _body = {
"type": _event[$ "type"],
"version": _event[$ "version"],
"condition": _event[$ "condition"],
"transport": {
"method": "websocket",
"session_id": string(global.twitch_session_id)
}
};
http_request(_url, "POST", _headers, json_stringify(_body));
__twitch_message("Subscribe request to ", _event[$ "type"], " sent");
};
}
Thank you very much for your help !