}
private GetOAuthUserResponse getGetOAuthUserResponse(String[] scopes)
throws OAuthRequestException {
ApiProxy.Environment environment = ApiProxy.getCurrentEnvironment();
GetOAuthUserResponse response = (GetOAuthUserResponse)
environment.getAttributes().get(GET_OAUTH_USER_RESPONSE_KEY);
String scopesKey = "[]";
if (scopes != null && scopes.length > 0) {
String[] scopesCopy = scopes.clone();
Arrays.sort(scopesCopy);
scopesKey = Arrays.toString(scopesCopy);
}
String lastScopesKey = (String) environment.getAttributes().get(GET_OAUTH_USER_SCOPE_KEY);
if (response == null || !Objects.equals(lastScopesKey, scopesKey)) {
GetOAuthUserRequest request = new GetOAuthUserRequest();
if (scopes != null) {
for (String scope : scopes) {
request.addScopes(scope);
}
}
Boolean requestWriterPermission = (Boolean) environment.getAttributes().get(
REQUEST_WRITER_PERMISSION_KEY);
if (requestWriterPermission != null && requestWriterPermission) {
request.setRequestWriterPermission(true);
}
byte[] responseBytes = makeSyncCall(GET_OAUTH_USER_METHOD, request);
response = new GetOAuthUserResponse();
response.mergeFrom(responseBytes);
environment.getAttributes().put(GET_OAUTH_USER_RESPONSE_KEY, response);
environment.getAttributes().put(GET_OAUTH_USER_SCOPE_KEY, scopesKey);
}
return response;
}