I am posting Events to Google Calendar using their REST API from Java (GAE), NOT the client library.
This works very well, except that non-ASCII characters are showing up as question marks.
Things I have done to try to address this (some are clutching at straws):
- The content-type is set to UTF-8: "Content-Type", "application/json; charset=UTF-8"
- I have tried URL encoding the "summary" (which is the Event title) field within the JSON body
- I tried html escaping the "summary" field within the JSON body
- Searched StackOverflow, and I found this reference that seems like the same problem, but it's in the context of PHP, not Java, so (I think) String handling is quite different, and therefore it doesn't seem to directly apply. Basically this one says make sure that the summary value itself is UTF-8 encoded, and uses a utf8_encode function for which there isn't a direct Java comparison
I realize that one answer is probably just to use the Java library, but for various reasons I don't want to do that unless I absolutely have to.
Any ideas please? Thank you.
EDIT TO ADD CODE:
I create a Scribe Request like this (and, yes, I know that this is not what Scribe is intended for...):
String url = String.format("https://www.googleapis.com/calendar/v3/calendars/%s/events", inTargetCalendar.getId());
OAuthRequest req = new OAuthRequest(Verb.POST, url);
req.addQuerystringParameter("access_token", <TOKEN>);
JSONObject jBody = new JSONObject();
jBody.put( "start", <START> );
jBody.put( "end", <END> );
jBody.put( "summary", getSummary() );
log.info("*** getSummary() is: " + getSummary());
jBody.put( "colorId", getColorId() );
req.addPayload(jBody.toString());
req.addHeader("Content-Type", "application/json; charset=UTF-8");
Note that in this example, when I look at my log file, the logs show (correctly):
*** getSummary() is: Côte Brasserie
I then post the request like this:
Response response=null;
try {
response = request.send();
} catch (...) {...}
Per notes above, this works perfectly, except that the "ô" doesn't show up correctly. Specifically when I look at the Event through the Google calendar website it looks like this:
C?te Brasserie
I.e. the "ô" shows up as a "?". This is the same for other non-ASCII characters (from what I have seen).