gpt4 book ai didi

Google Apps Script gives error "Something Went Wrong" when I try to authorize my own code(当我尝试授权我自己的代码时,Google Apps脚本出现错误“Something Wed Error”)

转载 作者:bug小助手 更新时间:2023-10-24 22:36:38 30 4
gpt4 key购买 nike



I'm very new to Google Apps Script, so I'm sorry if this is a super basic question. I've tried searching for similar questions, but the closest I could find didn't work. This person from two years ago seems to have a very similar problem, but there aren't any solutions listed.

我对Google Apps脚本非常陌生,所以如果这是一个超级基本的问题,我很抱歉。我试着搜索类似的问题,但我能找到的最接近的问题都不起作用。这个两年前的人似乎有非常相似的问题,但没有列出任何解决方案。


I'm using my personal Google account, and trying to use simple code to automate formatting of a Google Sheets spreadsheet that I created. I'm not trying to share access with anyone else. The smallest reproducible example is opening a fresh spreadsheet, clicking "Apps Script" under Extensions in the toolbar, pasting this into the code editor, clicking "save" and then "run":

我正在使用我的个人Google账户,并试图使用简单的代码来自动设置我创建的Google Sheets电子表格的格式。我不想与其他任何人共享访问权限。最小的可重现示例是打开一个新的电子表格,单击工具栏中扩展下的“Apps脚本”,将其粘贴到代码编辑器中,单击“保存”,然后单击“运行”:


function Untitled() {
var mySS = SpreadsheetApp.getActiveSpreadsheet();
}

When I run it, it says I have to give it permissions, so I click on my Google account in the pop-up. This window comes up, like in the first post I linked, saying "Google hasn't verified this app":

当我运行它时,它会告诉我必须给它权限,所以我在弹出窗口中点击了我的谷歌账户。这个窗口就会出现,就像我链接的第一个帖子中说的那样,“谷歌还没有验证这款应用程序”:


I click "Advanced," and then "go to Untitled project (unsafe)," but then a small black window comes up in the bottom-left of the pop-up comes up that says "Something went wrong. Please try again."

我点击“高级”,然后点击“转到无标题项目(不安全)”,然后弹出窗口的左下角出现一个黑色小窗口,上面写着“出现问题,请再试一次。”


I've tried clearing my browser cache/cookies/data, on the off-chance that that could help. I've also tried going through my Google Account settings, but didn't immediately see anything that would affect this. It occurs whether the spreadsheet is listed as private for only me, or if it's public, with anyone with the link able to edit.

我试着清理我的浏览器缓存/cookie/数据,希望这能有所帮助。我也试着检查了我的谷歌账户设置,但没有立即看到任何会影响这一点的东西。无论是将电子表格列为仅供我使用的私有电子表格,还是将其列为公共电子表格,只要具有该链接的任何人都可以编辑,都会发生这种情况。


I also tried adding /* @OnlyCurrentDoc */ directly above the function, which was mentioned in a lower answer in the first question linked above. This seems to bring me a page further, and gives me the 'this page is requesting these permissions' message, but when I click "allow," it gives me a similar error message.

我还尝试在函数的正上方添加/*@OnlyCurrentDoc*/,上面链接的第一个问题的较低答案中提到了这一点。这似乎给我带来了一个更进一步的页面,并给出了‘This Page is Requesting ThressPermises’消息,但当我单击“Allow”时,它会给我一个类似的错误消息。


Does anyone know why it's not allowing me to give it permission? Or alternatively, is there a different way to accomplish automated sheet formatting without needing to get the permissions? Thank you!

有人知道为什么它不允许我给它许可吗?或者,有没有其他方法可以在不需要获得权限的情况下完成自动工作表格式设置?谢谢!


更多回答
优秀答案推荐

I have many AppsScripts written for my spreadsheets and have never encountered this. I tested your workflow by clicking 'Run' in the AppsScript editor, and sure enough I got the permissions pop-up (that I have never seen before). I have a workaround you can use. Try testing in your spreadsheet instead of in AppsScript. For example, add this to your code:

我为我的电子表格编写了许多AppsScript,但从未遇到过这种情况。我测试了你的工作流程,点击了AppsScript编辑器中的‘Run’,果然我得到了权限弹出窗口(我以前从未见过)。我有一个变通办法,你可以用。尝试在您的电子表格中而不是在AppsScript中进行测试。例如,将以下代码添加到您的代码中:


function onEdit(e) {
Browser.msgBox('testing');
}

This is a function that will trigger any time the spreadsheet is edited. https://developers.google.com/apps-script/guides/triggers/

这是一个在编辑电子表格时随时触发的函数。Https://developers.google.com/apps-script/guides/triggers/


Then return to the spreadsheet that the script is tied to and type something in one of the cells, triggering an edit. You should get the popup saying 'testing' which will let you know that the AppsScript is connected and working. From here you can continue debugging via message boxes and editing your script as needed.

然后返回到该脚本所绑定的电子表格,并在其中一个单元格中键入某些内容,从而触发编辑。您应该会看到一个弹出窗口,上面写着‘Testing’,它会让您知道AppsScript已连接并且正在工作。从这里,您可以继续通过消息框进行调试,并根据需要编辑您的脚本。


Maybe the error is because you aren't running it through a spreadsheet when you're in the editor. That part I don't know.

错误可能是因为当您在编辑器中时,没有通过电子表格运行它。这一点我不知道。


更多回答

Thank you, that works!! And seems a lot better for my future use than opening the editor every time :)

谢谢,这很管用!!而且似乎比每次都打开编辑器更适合我将来的使用:)

If you don't wish to run a function for some reason but you know that you need to authorize the current script because you have changed the scopes in your manifest then you can force the authorization screen with a function that has no commands. function dummy(){//do nothing} You will always have to authorize scripts that force you in wider scopes. In fact, it is one of the things that people who wish to use your scripts will have to get used to if they wish to use scripts that have not been verified by Google.

如果您出于某种原因不想运行某个函数,但您知道您需要授权当前脚本,因为您已经更改了清单中的作用域,那么您可以使用一个没有命令的函数来强制授权屏幕。函数DUMMY(){//什么都不做}您必须始终授权在更大范围内强制您的脚本。事实上,如果希望使用未经Google验证的脚本,希望使用您的脚本的人将不得不习惯这一点。

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com