Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception: You do not have permission to call SpreadsheetApp.openById #4

Open
mark05e opened this issue Apr 5, 2022 · 0 comments
Open

Comments

@mark05e
Copy link

mark05e commented Apr 5, 2022

Exception: You do not have permission to call SpreadsheetApp.openById. Required permissions: https://www.googleapis.com/auth/spreadsheets
    at BBLog_._useSpreadsheet(BBLog:559:34)
    at BBLog_(BBLog:212:30)
    at getLog(BBLog:101:10)

I've been seeing this message on the stackdriver/execution logs after I started using BBLog code as a library. Trying to figure out why this error message keeps showing up. I have tried to setup oauthScopes on the library and also in the calling script (appsscript.json) but it doesnt seem to help.

  "oauthScopes": [
      "https://www.googleapis.com/auth/userinfo.email",
      "https://www.googleapis.com/auth/drive",
      "https://www.googleapis.com/auth/drive.file",
      "https://www.googleapis.com/auth/drive.readonly",
      "https://www.googleapis.com/auth/spreadsheets",
      "https://www.googleapis.com/auth/spreadsheets.readonly"
  ],

The code that seems to be causing the exception is ...

// snippet
/********************************************************************************
 * Private Methods
 *****************/

/**
 * Allows logging to a Google spreadsheet. Sets the log sheet, creating 
 * one if it doesn't exist
 *
 * @param {string} key The spreadsheet key [OPTIONAL, DEFAULT: active spreadsheet]
 * @param {string} sheetName The name of the sheet 
 * @param {boolean} hideLog
 */
 
BBLog_.prototype._useSpreadsheet = function(key, sheetName, hideLog) {

  var spreadsheet;

  if (typeof key !== 'undefined' && key !== '') {  
    spreadsheet = SpreadsheetApp.openById(key);  // 👈 this line over here
  } else {
    spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  }
// snippet

My log configuration is ...

  var log = BBLog.getLog({
    level: BBLog.Level.ALL,  
    sheetName: 'Log',
    displayUserId: BBLog.DisplayUserId.EMAIL_FULL,
    sheetId: '15oZPWqurBBJYHaTLxNkmKCcDf8se9vyXXXXXXXXXX',
    lock: LockService.getScriptLock()
  });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant