Giter VIP home page Giter VIP logo

bblog's People

Contributors

andrewroberts avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

bblog's Issues

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

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

TypeError: Cannot read property 'replace' of undefined

I tried to import the BBLog.gs file alone as a library and try to execute a test function - I get an error inside the console

The function I used to test is

function myFunction() {
  var lock = LockService.getScriptLock();
  var log = BBLog.getLog({
    level: BBLog.Level.ALL,  
    sheetName: 'Log',
    displayFunctionNames: BBLog.DisplayFunctionNames.YES,
    displayUserId: BBLog.DisplayUserId.EMAIL_FULL,
    lock: lock
  });
  log.info('Test log to GSheet at INFO level');
}

The error inside the console

TypeError: Cannot read property 'replace' of undefined
BBLog_._getFunctionName                @ BBLog.gs:908
convertUsingDefaultPatternLayout       @ BBLog.gs:871
BBLog_._log                            @ BBLog.gs:780
BBLog_.info                            @ BBLog.gs:331

and I get this log line inserted on the sheet

2022-03-24 09:42:36:600 -0400 000383 [email protected] INFO     at BBLog_.info (BBLog:331:8) Test log to GSheet at INFO level

In another scenario, when I add the library directly to the sheet and run a modified test function...

function myFunction() {
  var lock = LockService.getScriptLock();
  var log = getLog({
    level: Level.ALL,  
    sheetName: 'Log',
    displayFunctionNames: DisplayFunctionNames.YES,
    displayUserId: DisplayUserId.EMAIL_FULL,
    lock: lock
  });
  log.info('Test log to GSheet at INFO level');
}

I get this output on the console

2022-03-24 10:15:33:363 -0400 000881 [email protected] INFO     at myFunction (Tests:11:7) Test log to GSheet at INFO level

and this line on the sheet

2022-03-24 10:15:32:819 -0400 000337 [email protected] INFO     at BBLog_.info (BBLog:331:8) Test log to GSheet at INFO level

I am wondering if this is because the configuration of depreciated runtime you have on your appsscript.json file?

  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "DEPRECATED_ES5"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.