当我尝试在Google Apps 域中模拟用户以使用 setServiceAccountUser()对Google Drive API进行身份验证时,我得到的响应为
com.google.api.client.auth.oauth2.TokenResponseException: 403 OK { "error" : "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();
提前致谢 !
拉姆·巴拉吉·苏拜扬。