When i try to impersonate a user in Google Apps Domain to authenticate Google Drive API using setServiceAccountUser() i get a response as
com.google.api.client.auth.oauth2.TokenResponseException: 403 OK { "error" : "access_denied", "error_description" : "Requested client not authorized." }
Below is my code :
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();
Thanks in advance !
Ram Balaji Subbaiyan .