I have the following issue. Through PHP, I create a copy of a Google Doc
$documentId = 'ID';
$googleAccountKeyFilePath = __DIR__ . '/service_key.json';
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $googleAccountKeyFilePath);
$client = new Google_Client();
$client->setApplicationName('Some name');
$client->setScopes([Google_Service_Docs::DOCUMENTS, Google_Service_Drive::DRIVE]);
$client->setAccessType('offline');
$client->setAuthConfig($googleAccountKeyFilePath);
$driveService = new Google_Service_Drive($client);
$originalDocument = $driveService->files->get($documentId);
$copyDocument = new Google_Service_Drive_DriveFile(array('name' => $_GET['domain'].' Title: ' . $_GET['date_start'].' - '.$_GET['date_end']));
$newDocument = $driveService->files->copy($documentId, $copyDocument); //copying document
$newDocumentId = $newDocument->getId();
$driveService->permissions->create($newDocumentId, new Google_Service_Drive_Permission(array('type' => 'anyone', 'role' => 'writer')));
The document is successfully created, and it contains an AppScript attached to the original, for example:
function onOpen() {
const ui = DocumentApp.getUi();
ui.createMenu('Addition')
.addItem('findSynonyms', 'findSynonyms')
.addToUi();
}
But the menu item does not appear, and when manually started, there’s an error:
Error
The script cannot be run because it is owned by a service account. Please copy or transfer the project to a valid account before running.
How can I fix this? What am I doing wrong? I am a bit far from all the policies of rights in App Scripts. If you can explain in more detail, I would be very grateful!”
appsscript.json:
{
"timeZone": "Europe/Kiev",
"dependencies": {
"enabledAdvancedServices": [{
"userSymbol": "Docs",
"serviceId": "docs",
"version": "v1"
}, {
"userSymbol": "Drive",
"serviceId": "drive",
"version": "v3"
}]
},
"webapp": {
"access": "DOMAIN",
"executeAs": "USER_ACCESSING"
},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8"
}