OAuthRequest _request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, _request);
Response _response = _request.send();
if (_response.getCode() != 200)
throw new OAuthException("Can query account information.");
String contentType = _response.getHeader("Content-Type");
if (contentType == null) contentType = "";
//String charset = "";
int semicolonPos = contentType.indexOf(';');
if (semicolonPos > 0) {
String _charset = contentType.substring(semicolonPos + 1).trim();
if (_charset.startsWith("charset")) {
//charset =
_charset.substring(_charset.indexOf('=') + 1);
}
contentType = contentType.substring(0, semicolonPos);
}
Map<String, String> responseAttributes = null;
String response = _response.getBody();
if ("application/json".equals(contentType) || (response.startsWith("{") && response.endsWith("}"))) {
JSONObject jsonResponse = new JSONObject(response);
if (jsonResponse != null) {
if (jsonResponse.has("error")) {
throw new OAuthException("Error getting access token: " + System.getProperty("line.separator") + jsonResponse.toString());
}
responseAttributes = parseJSONObject(jsonResponse);
}
} else if ("text/plain".equals(contentType) || (response.contains("=") && response.contains("&"))) {
//responseAttributes = OAuthUtil.parseQueryString(response);
}
if (responseAttributes == null)
throw new OAuthException("Get response, but no account information.");
String id = responseAttributes.get("id");
String accountName = id + "@google.com";