in into google drive api with service account credential, to upload file for a specific user j********@gmail.com.
I create my account service credential in google developer API console. i add permission for user j****@gmail.com i authorize my app for j****@gmail.com
but sometimes autetication fails with this messagge
Google_Service_Exception
{
"error": "unauthorized_client",
"error_description": "Client is unauthorized to retrieve access tokens using this method."
}
here's my code for auth
if ($credentials_file = checkServiceAccountCredentialsFile()) {
// set the location manually
$client->setAuthConfig($credentials_file);
} elseif (getenv('GOOGLE_APPLICATION_CREDENTIALS')) {
// use the application default credentials
$client->useApplicationDefaultCredentials();
} else {
echo missingServiceAccountDetailsWarning();
return;
}
$client->setSubject('j******@gmail.com');
$client->setScopes(['https://www.googleapis.com/auth/drive']);
$service = new Google_Service_Drive($client);
$files = $service->files->listFiles();