Ошибка кодировки UTF-8 для ведения журнала с помощью GoogleJAVA

Программисты JAVA общаются здесь
Anonymous
Ошибка кодировки UTF-8 для ведения журнала с помощью Google

Сообщение Anonymous »

Код: Выделить всё

public static String getToken(String code) throws ClientProtocolException, IOException {
String response = Request.Post(Constants.GOOGLE_LINK_GET_TOKEN)
.bodyForm(  Form.form().add("client_id", Constants.GOOGLE_CLIENT_ID).add("client_secret", Constants.GOOGLE_CLIENT_SECRET)
.add("redirect_uri", Constants.GOOGLE_REDIRECT_URI)
.add("code", code)
.add("grant_type", Constants.GOOGLE_GRANT_TYPE)
.build()
)
.execute().returnContent().asString(Charset.forName("UTF-8"));
JsonObject jobj = new Gson().fromJson(response, JsonObject.class);

String accessToken = jobj.get("access_token").toString().replaceAll("\"", "");

return accessToken;
}

public static Account getUserInfo(final String accessToken) throws ClientProtocolException, IOException {
String link = Constants.GOOGLE_LINK_GET_USER_INFO + accessToken;

// Take Response Google API
String response = Request.Get(link).execute().returnContent().asString(Charset.forName("UTF-8"));

JsonObject jobj = new Gson().fromJson(response, JsonObject.class);

String fullName = jobj.get("name").getAsString();
System.out.println("Full Name: " + fullName);

Account googlePojo = new Gson().fromJson(response, Account.class);
googlePojo.setFullName(fullName);

return googlePojo;
}
Вывод:

Код: Выделить всё

Full Name: Ng?c Khánh Hu?nh
Я не знаю, что utf-8 не работает. Я не уверен, что это charset.foName("Utf-8") правильное или я что-то не так в функции getUserInfor

Подробнее здесь: https://stackoverflow.com/questions/790 ... ith-google

Вернуться в «JAVA»