How to deal with execution error?

57 views
Skip to first unread message

Dongwook Seo

unread,
Jun 11, 2023, 1:20:07 PM6/11/23
to Google Apps Script Community
Can somebody help me deal with this issue?
I am trying to send email with a apreadsheet but this error keeps apprearing.
It looks like a permission issue but I don't know how to solve this one.

오전 2:19:52
알림
실행이 시작됨
오전 2:19:53
오류
Exception: You do not have permission to call SpreadsheetApp.openById. Required permissions: https://www.googleapis.com/auth/spreadsheets
AutoEmailSend_230608.gs:11


My code is like below
function convertAndSendExcelFile() {
  var recipientEmails = ["a", "b"]; // Email address
  var subject = "title"; // Email title
  var body = "contents"; // Email body

  // Google Spreadsheet set
  var spreadsheetId = "idid"; // spreadsheet ID
  var sheetName = "Indirect"; // sheet name

  // Get spreadsheet data
  var spreadsheet = SpreadsheetApp.openById(spreadsheetId);
  var sheet = spreadsheet.getSheetByName(sheetName);
  var dataRange = sheet.getDataRange();
  var data = dataRange.getValues();

  // transforminito an excel file
  var excelFile = DriveApp.createFile("data.xlsx", dataRange.getBlob().getAs(MimeType.MICROSOFT_EXCEL));

  // send email
  MailApp.sendEmail({
    to: recipientEmails.join(", "),
    subject: subject,
    body: body,
    attachments: [excelFile.getAs(MimeType.MICROSOFT_EXCEL)]
  });

  // delete the file
  excelFile.setTrashed(true);
}

cbmserv...@gmail.com

unread,
Jun 11, 2023, 8:38:18 PM6/11/23
to google-apps-sc...@googlegroups.com

Either you do not have edit access to that spreadsheet or you have not added that permission to your script.

 

Run it manually and when it asked you to authorize it, do the authorization required to allow it to run.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/a3f03fd2-efd0-4735-84d7-03fe4f030a96n%40googlegroups.com.

Dongwook Seo

unread,
Jun 13, 2023, 10:24:30 AM6/13/23
to Google Apps Script Community
Thanks for the answer.

But I'd like to know how to solve this,
as I keep running it it gives me the same error message without any popup.

can you suggest a way to solve this?
or let me know what keyword I should search on.

I am very bigginer of this apps script.

Ed Sambuco

unread,
Jun 13, 2023, 11:49:19 AM6/13/23
to google-apps-sc...@googlegroups.com
OK .. look in the script's manifest files (appsscript.json) and you should see a section like this:

"oauthScopes": [
  ],

This is where the applicable permission scopes are put. Add the first one above if you don't see it in your manifest file.

I don't have to do this normally because on first execution, usually Google does a decent job of assigning permissions.

CBMServices Web

unread,
Jun 13, 2023, 2:06:50 PM6/13/23
to google-apps-sc...@googlegroups.com
Did you try running the script manually?

Reply all
Reply to author
Forward
0 new messages