Drive SDK service account error "Authenticated user did not install application with client ID ..."

I am trying to create a Google Drive application that can run in the background (for example, cronjob), without any user interaction, using the Google Drive SDK service account, but this gives me this error and I don’t understand why:

Error when calling POST https://www.googleapis.com/upload/drive/v1/files?uploadType=multipart : (403) The authenticated user did not install the application with the client ID {my_client_id}

In the Google APIs Console, I have activated the Drive API and the Drive SDK. On the SDK tab of the drive, I installed all the necessary information. I also published my tester app only in the Chrome Web Store and installed it on my Google Chrome, and the app name appeared in the Create menu on Google Drive.

This is a piece of code:

<?php require_once dirname(__FILE__).'/google-api-php-client/src/apiClient.php'; require_once dirname(__FILE__).'/google-api-php-client/src/contrib/apiDriveService.php'; $apiClient = new apiClient(); $apiClient->setClientId(DRIVE_CLIENT_ID); $apiClient->setClientSecret(DRIVE_CLIENT_SECRET); $apiClient->setAssertionCredentials(new apiAssertionCredentials( OAUTH2_EMAIL, array('https://www.googleapis.com/auth/drive.file'), file_get_contents(SERVICE_ACCOUNT_PRIVATEKEY_FILE)) ); $apiDriveService = new apiDriveService($apiClient); $file = new DriveFile(); $file->setTitle('filename.txt'); $file->setMimeType('text/plain'); $createdFile = $apiDriveService->files->insert($file, array( 'data' => 'file content goes here....', 'mimeType' => 'text/plain' )); ?> 

From what I understand, the application can use the service account for the Google Drive SDK on behalf of the user. Does this mean that the user is not asked an authentication question (permission request)? Then how is the application authenticated? Or is my understanding probably wrong? Please help enlighten me here.

+3
source share
1 answer

Service accounts are not supported on the drive SDK due to its security model.

I would suggest to open (or create) a file from the Google Drive web interface with your application and save the extracted access and update the tokens that you will receive after the authorization of the OAuth 2.0 stream is completed.

From your cron job, simply download these credentials to send authorized requests to the disk API on behalf of your user.

+2
source

All Articles