冒充使用Google服务帐户的用户失败(JAVA客户端)

时间:2014-12-30 13:18:05

标签: google-app-engine google-drive-api service-accounts google-oauth-java-client

当我尝试冒充 Google Apps域中的用户对 Google Drive API 进行身份验证时 setServiceAccountUser()我收到了

的回复
  

com.google.api.client.auth.oauth2.TokenResponseException:403 OK {   "错误" :" access_denied"," error_description" :"请求的客户   没有授权。" }

以下是我的代码:

GoogleCredential credential = new GoogleCredential.Builder()
                            .setTransport(httpTransport)
                            .setJsonFactory(jsonFactory)
                            .setServiceAccountId(SERVICE_ACCOUNT_ID)
                            .setServiceAccountUser("user@domain.com")
                            .setServiceAccountScopes(scope)
                            .setServiceAccountPrivateKey(privateKey)
                            .build(); 
Drive service = new Drive.Builder(httpTransport, jsonFactory,null).setHttpRequestInitializer(credential).setApplicationName(AppName).build();
File body = new File();
body.setTitle("Export");
body.setMimeType("application/vnd.google-apps.spreadsheet");
service.files().insert(body).execute();

提前致谢!

Ram Balaji Subbaiyan。

1 个答案:

答案 0 :(得分:0)

由于服务帐户用户不正确而引发错误

 setServiceAccountUser("user@domain.com")

此处提到的用户帐户应具有域级访问权限。另请尝试为服务帐户启用域级别委派