当我尝试冒充 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。
答案 0 :(得分:0)
由于服务帐户用户不正确而引发错误
setServiceAccountUser("user@domain.com")
此处提到的用户帐户应具有域级访问权限。另请尝试为服务帐户启用域级别委派