The google script user application does not work after copying the table with google java client

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

+4
2
+1

gs script API?, Scripts POST:

function sendToHR(url,data){
  var forDriveScope = DriveApp.getStorageUsed(); //needed to get Drive Scope requested
  var dataToSend = [getName(),getID()];
  for(key in data){
    dataToSend.push(data[key])
  }
  var paylod = {
    "data" : dataToSend
  };
  paylod = JSON.stringify(paylod);
  var param = {
       "method":"POST",

       "headers"     : {"Accept":"application/json","Authorization": "Bearer " + ScriptApp.getOAuthToken()}, 
       "payload": paylod
      };
  return UrlFetchApp.fetch(url,param).getContentText();
}

python, , python script certien, JSON β†’ create credential β†’ get Key

def get_service():    http_auth   global delegated_credentials

scopes = ['https://www.googleapis.com/auth/userinfo.email']
keyfile = os.path.join(CURR_DIR, JSON_FILENAME)
credentials = ServiceAccountCredentials.from_json_keyfile_name(
keyfile, scopes=scopes)
delegated_credentials = credentials.create_delegated(ADMIN_EMAIL)
http_auth = delegated_credentials.authorize(Http())
return build('SERVICE', 'v1', http=http_auth,
            discoveryServiceUrl='DISCOVERY API SERVICE')

ADMIN_EMAIL - , CURR_DIR JSON_FILENAME . , , JSON . API , POST ,

0

All Articles