App Script Go快速入门修改401错误

huangapple go评论96阅读模式
英文:

App Script Go Quickstart modification 401 error

问题

我正在尝试这个关于Go和App Script的教程,它完美地运行了。但是当我修改代码以访问电子表格时,Go部分就不执行脚本,而是出现401错误。这是我的Go代码(基本上是教程中的代码,但为了在我的App Script上“工作”,我做了一些修改):http://pastebin.com/28S5tVY2

我不知道在为脚本创建凭据时是否犯了错误(我已经多次重新做过,但没有成功),或者在修改过程中是否遗漏了某些内容。非常感谢任何帮助。

英文:

I am trying out this tutorial on Go and App Script and it works perfectly but the moment I modified the code to access a spreadsheet the go part doesn't execute the script but give a 401 error. Here is my go code (basically code from the tutorial but changed a few things for it to 'work' on my app script) http://pastebin.com/28S5tVY2

I don't know if I made a mistake when creating credentials for the script (I have redone this severally with no success) or if I missed something while doing the modification. Any help will be highly appreciated.

答案1

得分: 1

根据 @Mogsdad 的建议,我研究了如何添加作用域。在目标 App Script 上,点击文件 >> 项目属性 >> 作用域,以获取需要添加的作用域。一个作用域的示例是 "https://www.googleapis.com/auth/spreadsheets"。

在 Golang 代码中,可以像这样添加作用域:

config, err := google.ConfigFromJSON(b, "https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/spreadsheets")

希望对某人有所帮助 App Script Go快速入门修改401错误

英文:

As suggested by @Mogsdad, I looked into adding scopes. On the target App Script, click on File >> Project Properties >> Scopes to get what scopes you need to add. An example of a scope is "https://www.googleapis.com/auth/spreadsheets".

On the Golang code, add the scope like so:

config, err := google.ConfigFromJSON(b, https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/spreadsheets") 

Hope this helps someone App Script Go快速入门修改401错误

huangapple
  • 本文由 发表于 2015年11月11日 16:12:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/33646511.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定