I have a google spreadsheet template with a custom add-on that I am trying to copy
def copyTemplateSpreadsheet(Drive driveService) {
File templateCopy = new File()
templateCopy.setName("excel-template")
def copiedFile = driveService.files().copy(templateSpreadsheetId, templateCopy).execute()
setCorrectPermission(driveService, copiedFile.getId())
copiedFile
}
private void setCorrectPermission(Drive driveService, def fileId) {
Permission newPermission = new Permission();
newPermission.setType("anyone");
newPermission.setRole("writer");
driveService.permissions().create(fileId, newPermission).execute();
}
The problem is that the copied table broke the add-in (does not appear in the add-in menu). There is correct additional code in the script editor, but when I try to run any function, I get an error
"We're sorry, a server error occurred. Please wait a bit and try again"
Keep in mind that the same code works well in my template spreadsheet. Even if I delete all the code and leave the onOpen function empty, the error still appears.
, Google Drive (drive.google.com), , Google API Explorer (https://developers.google.com/drive/v3/reference/files/copy#try-it). , , sdk ( , java one - )
, google, , https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount
Drive getDriveService() throws GeneralSecurityException, IOException, URISyntaxException {
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(G_SERVICE_EMAIL)
.setServiceAccountScopes(Arrays.asList(DriveScopes.DRIVE))
.setServiceAccountPrivateKeyFromP12File(PKC_12_FILE)
.build();
Drive service = new Drive.Builder(httpTransport, jsonFactory, null)
.setHttpRequestInitializer(credential)
.build();
return service;
}
, , , .
- ? , .
, , API