Reputation: 1
I'm trying to read files using a Service Account from shared folders using Google API in PHP codes. It works when reading from the shared folders in MyDrive, but not in other shared folders from another department.
The only difference is that the Service Account has "Editor" permission in MyDrive, and "Content Manager" in the shared folders.
My understanding is that it should be able to get all the files that are shared to the Service Account.
Is there any permission or settings that need to be done on the shared folders?
$credentialsFilePath = 'creds.json';
$client = new Google_Client();
$client->setAuthConfig($credentialsFilePath);
$client->addScope(Google_Service_Drive::DRIVE);
$client->setApplicationName("GoogleDrive");
$client->refreshTokenWithAssertion();
$token = $client->getAccessToken();
$accessToken = $token['access_token'];
//get file ID from Google Drive
$csv_file_name = "File_123.csv";
$driveService = new Google_Service_Drive($client);
$files = array();
$parameters = array(
'q' => "mimeType='text/csv'",
"orderBy" => "modifiedDate desc"
);
$results = $driveService->files->listFiles($parameters);
foreach($results->getItems() as $file){
if($file->title == $csv_file_name){
$drive_file_id = $file->id;
break;
}
}
if(empty($drive_file_id)){
$valErr .= 'File no found!';
}
Upvotes: 0
Views: 88