Skip to content

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

@mark05e

Description

@mark05e
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()
  });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions