From 130148d6a8d50d8d0332180df6ca40c648eb2d80 Mon Sep 17 00:00:00 2001 From: Nick Pantelidis Date: Fri, 9 Sep 2022 10:02:03 +0300 Subject: [PATCH] UTF-8 encoding to rules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without this addition the rules cannot accept words that contain non ASCII characters (for example the word siccità) and the API returns the error "{"errors":[{"parameters":{},"message":"Invalid JSON"}],"title":"Invalid Request","detail":"One or more parameters to your request was invalid.","type":"https://api.twitter.com/2/problems/invalid-request"}" --- Filtered-Stream/FilteredStreamDemo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Filtered-Stream/FilteredStreamDemo.java b/Filtered-Stream/FilteredStreamDemo.java index ea23fb1..629a941 100644 --- a/Filtered-Stream/FilteredStreamDemo.java +++ b/Filtered-Stream/FilteredStreamDemo.java @@ -89,7 +89,7 @@ private static void createRules(String bearerToken, Map rules) t HttpPost httpPost = new HttpPost(uriBuilder.build()); httpPost.setHeader("Authorization", String.format("Bearer %s", bearerToken)); httpPost.setHeader("content-type", "application/json"); - StringEntity body = new StringEntity(getFormattedString("{\"add\": [%s]}", rules)); + StringEntity body = new StringEntity(getFormattedString("{\"add\": [%s]}", rules), "UTF-8"); httpPost.setEntity(body); HttpResponse response = httpClient.execute(httpPost); HttpEntity entity = response.getEntity();