API Endpoint Returning Gibberish

Hi everyone,

I have been working with the Twitch API for some time now and have made a API-V5 Java handler for handling any requests between my bot and the Twitch API.

However, when i do a request for subscribers using the endpoint: /channels/[CHANNEL_ID]/subscriptions
Instead of getting back something that makes sense, like a proper error message… I’m getting random rubbish, anyone have any ideas?

It’s the only endpoint causing this issue.

Pretty sure this is a GSON problem. The endpoint works without issue for me and returning a JSON object. I found this with a quick Google: http://stackoverflow.com/questions/9598707/gson-throwing-expected-begin-object-but-was-begin-array

That’s what i thought originally, so I added a debug line just above the GSON event:

public void onFailure(int statusCode, String content) {
System.out.println(“Error (”+statusCode+"): " + content);
Gson gson = new Gson();
handler.onFailure(gson.fromJson(content, TwitchErrorResource.class));

The content string was the one returning the random symbols and taking place prior to any other event. It’s just a raw output from the API.

Hm. I don’t see your error printing in your screenshot. Your System.out.println has the string “Error (” in it, and the error in your screenshot is "Error: " with no parentheses, status code, etc.

Sorry about that… it was prior to me adding the ("+statusCode+") section.

Sometimes when I boot the bot it returns the proper response:
Error (403): {“error”:“Forbidden”,“status”:403,“message”:“The current authorization is not valid for this context”}

Other times it returns gibberish, even when I haven’t changed any source code.

The highlighted section of the screenshot above shows the error message

Could it be responding with GZIP encoded content? I mean it shouldn’t do that unless you tell it to in the Accept-Encoding header, but that’s what I think of when I hear “gibberish”.

Not sure how only header types ive got going are these:

connection.setRequestProperty("Client-ID", TwitchAPI.CLIENT_ID);
connection.setRequestProperty("Accept", "application/vnd.twitchtv.v5+json");
connection.setRequestProperty("Authorization", "OAuth " + event.getTwitch().getAuth());
connection.setRequestProperty("Content-Type", "application/json");

Well as I said, the API may send a GZIP encoded response, even if it shouldn’t. I encountered APIs like that before. In fact, I am receiving a response on the /kraken/channels/<id>/subscriptions endpoint which contains a Content-Encoding: gzip, even if I don’t send an Accept-Encoding header. I can’t test if the content is actually GZIP encoded since I don’t have access to a partnered channel. On other Twitch API endpoints (the ones I happen to use at least) it seems fine.

1 Like

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