EDIT: When copying files that the service account created via the API, the copy goes through, but this error persists and the file id in the error corresponds to the copy. When copying a file the service account does not own (but has edit access to), the copy does not occur and the file id in the error is for the original file.
The service account does not seem to have visibility outside of files that it created via the API, and does not have visibility to copies of those files.
=-=-=-=-=-=-=-=-=-=-=-=-=-
I am getting the same error as this question: Google Drive API copy() - 404 error except my setup is a little different.
Creating files works fine.
I am trying to create documents via copy that will not be owned by users but still give them read / write / no download access. I'll be happy if it just copies for now.
Here is the code:
$service = GoogleDrive::connect();
$copy = new \Google_Service_Drive_DriveFile();
$copy->setTitle($documentName);
try {
$createdFile = $service->files->copy($source_id, $copy);
} catch (\Exception $e) {
print "An error occurred: " . $e->getMessage();
}
And the output:
An error occurred: Error calling POST https://www.googleapis.com/drive/v2/files/1RXglHS8P4Klcn28WTsf-QHj9BuBIV0AY3R6PeJitqcM/copy: (404) File not found: 1PKaE72BI0ux3uAv3vCKv4pAT_jsxhJ5uZOY0F1sEcNw
It seems like there's an issue with permissions on the destination file? How can I verify if there's a permission or authentication issue? I'm logged in with OAuth just fine.
Here is the client connection code:
static public function connect()
{
self::$shared_folder = config('google.SharedFolder');
$client_email = config('google.ServiceAccountEmail');
// See if we need to recreate the client
if (!GoogleDrive::$client) {
$private_key = file_get_contents(config('google.ServiceAccountKeyFile'));
GoogleDrive::$client = new \Google_Client();
GoogleDrive::$client->setApplicationName(GoogleDrive::$app_name);
$credentials = new \Google_Auth_AssertionCredentials(
$client_email,
GoogleDrive::$scope,
$private_key
);
GoogleDrive::$client->setAssertionCredentials($credentials);
}
// Always see if the token is expired
if (GoogleDrive::$client->getAuth()->isAccessTokenExpired()) {
GoogleDrive::$client->getAuth()->refreshTokenWithAssertion();
}
$_SESSION['service_token'] = GoogleDrive::$client->getAccessToken();
return new \Google_Service_Drive(GoogleDrive::$client);
}