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;}
The out put isFull Name: Ng?c Khánh Hu?nh
I dont know utf-8 is not work. I not sure this charset.foName("Utf-8") is correct or i wrong something in the getUserInfor function