【问题标题】:"Authorization is required to perform that action" all of a sudden after no change to code在没有更改代码后突然“需要授权才能执行该操作”
【发布时间】:2015-05-28 08:20:05
【问题描述】:

我在这里查看了答案:How do I stop the error, Authorisation is required to perform that action in Google Script。这并不能解决我的问题,因为我没有更改任何代码,并且在第一次运行代码时我已经授权了该代码。突然间我收到Authorization is required to perform that action 错误。

我也试过这个链接https://developers.google.com/apps-script/troubleshooting#common_errors 并在编辑器function test() { var a=1} 中运行了一个空白函数。这运行正常,没有提示我授权脚本并且没有错误。因此,按照 Google 的说明操作后:To authorize the script, open the Script Editor and run any function. 我仍然收到Authorization is required to perform that action 错误。

我没有做任何花哨的事情。该脚本只有一个.gs文件,该文件只有一个功能。我没有使用任何高级服务,也没有将其链接到任何库。

更新:我尝试制作文件的副本,然后再次进入脚本编辑器运行代码。这次授权弹出在那里,所以我点击继续。如下所示:代码想要

View and manage the files in your Google Drive. Send email as you Connect to an external service

我点击“接受”。代码开始运行,2 秒后Authorization is required to perform that action. 现在每次我尝试运行代码时,它甚至都没有给我弹出授权。它只是给了我错误。

这里是代码的 oauth 部分。其余的代码只是多几行。

  var oauthConfig = UrlFetchApp.addOAuthService("google");
  var scope = "https://docs.google.com/feeds/";

  //make OAuth connection
  oauthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
  oauthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
  oauthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
  oauthConfig.setConsumerKey("anonymous");
  oauthConfig.setConsumerSecret("anonymous");

  //get request
  var request = {
    "method": "GET",
    "oAuthServiceName": "google",
    "oAuthUseToken": "always",
    "muteHttpExceptions": true
  };

【问题讨论】:

  • 您在使用任何高级谷歌服务吗?
  • 我查看了脚本编辑器中的资源部分。一切都关闭了。我没有使用任何高级服务。
  • 之前的代码是否有效?如果没有,您可以发布它以便我们检查错误是否在您的代码中?
  • 是的,在发生这种情况之前,它工作了大约一个月。我现在已经包含了代码的 oauth 部分。
  • 成绩单/日志中有什么?

标签: google-apps-script authorization


【解决方案1】:

UrlFetchApp 中的 oauthConfig 已被弃用。它于 6 月 26 日关闭。以下链接将向您展示如何将代码从 oauthConfig 迁移到 Oauth1 库。
https://developers.google.com/apps-script/migration/oauth-config

编辑: 从 cmets 看来,您希望将电子表格保存为驱动器中的 pdf。这是一个可以做到这一点的sn-p代码。

  var ss = SpreadsheetApp.openById(fileId);
  var blob = ss.getBlob().setName("new_file_name.pdf");
  DriveApp.createFile(blob);

【讨论】:

猜你喜欢
  • 2013-04-29
  • 1970-01-01
  • 1970-01-01
  • 2021-08-25
  • 2018-09-04
  • 1970-01-01
  • 2013-02-19
  • 2019-04-22
  • 1970-01-01
相关资源
最近更新 更多