You do not have permission to call openById

前端 未结 4 1601
抹茶落季
抹茶落季 2020-11-30 08:48

Problem: When I run the script, Google tells me,

You do not have permission to call openById

I had copied a script from anothe

相关标签:
4条回答
  • 2020-11-30 09:13

    I thought that I would throw in a similar issue that I had which brought me to this question, where I received the error You don't have permission to call by openById. In my case I was trying to call functions from translate.gs which I copied from this example:

    https://developers.google.com/apps-script/quickstart/docs

    Note that at the top of translate.gs

    /**
     * @OnlyCurrentDoc
     *
     * The above comment directs Apps Script to limit the scope of file
     * access for this add-on. It specifies that this add-on will only
     * attempt to read or modify the files in which the add-on is used,
     * and not all of the user's files. The authorization request message
     * presented to users will reflect this limited scope.
     */
    

    The culprit here is the @OnlyCurrentDoc comment. See here for reference:

    https://developers.google.com/apps-script/guides/services/authorization

    Removing @OnlyCurrentDoc fixed this issue for me

    0 讨论(0)
  • 2020-11-30 09:15

    Nevermind, I figured it out!

    The method openByID can be called from a "Blank Project" but not a "Custom Functions in Sheets" nor a "Google Sheets Add-on" project.

    I thought a "Blank Project" would create a project that was not connected to my spreadsheet, but I was wrong. The Blank Project is connected to my spreadsheet. The other types of projects that I tried to use seem to be limited-scope versions of script projects, not able to carry out some GAS methods.

    0 讨论(0)
  • 2020-11-30 09:19

    You just have to copy the script content into a notes document, then delete all the functions into the script. Close the spreadsheet, and put the content into the notes document again into your script, when you execute the script again, Google will asks you agree to run the script, and that's it. Some kind of GAS classes needs update permissions to your script.

    0 讨论(0)
  • 2020-11-30 09:24

    I found this official note which I believe clears up what caused the issue.

    If your function is a custom function, that is one which can be used like a regular spreadsheet function in the sheet itself, then it has limited access to things and cannot open other spreadsheets.

    The same script can however open other spreadsheets from a menu button or similar.

    Link: Documentation at developers.google.com

    0 讨论(0)
提交回复
热议问题