【问题标题】:how to fix Authorization error on google apps script?如何修复谷歌应用脚​​本上的授权错误?
【发布时间】:2018-10-10 16:04:37
【问题描述】:

我第一次尝试谷歌应用脚​​本并从谷歌应用脚​​本文档运行以下脚本

function createAndSendDocument() {
  // Create a new Google Doc named 'Hello, world!'
  var doc = DocumentApp.create('Hello, world!');

  // Access the body of the document, then add a paragraph.
  doc.getBody().appendParagraph('This document was created by Google Apps Script.');

  // Get the URL of the document.
  var url = doc.getUrl();

  // Get the email address of the active user - that's you.
  var email = Session.getActiveUser().getEmail();

  // Get the name of the document to use as an email subject line.
  var subject = doc.getName();

  // Append a new string to the "url" variable to use as an email body.
  var body = 'Link to your doc: ' + url;

  // Send yourself an email with a link to the document.
  GmailApp.sendEmail(email, subject, body);
}

但是当我运行它时,我得到一个错误 Error: invalid_client when continue to authorization required.

【问题讨论】:

    标签: google-apps-script


    【解决方案1】:

    此代码有效,您使用的具体程序是什么?

    你看到授权请求弹窗了吗?

    您是否使用 gmail 帐户登录?

    您在帖子中写的消息是确切的错误消息吗?

    你能看一下执行记录吗? (见下文)

    【讨论】:

    • 是的,我登录了 gmail。是的,我看到了授权请求弹出窗口,但是当我点击继续时,它向我显示一个错误 Error: invalid_client 我尝试了执行脚本,但它显示了一个空白的执行脚本窗口。
    • Error: invalid_client Request Details cookie_policy_enforce=false scope=googleapis.com/auth/userinfo.email mail.google.com googleapis.com/auth/documents response_type=code gsession redirect_uri=script.google.com/oauthcallback access_type=offline approval_prompt=force state=ACjPJvHXjr0fueAIE7-4DWYNvFI0Y7WJQ5M9VX0erjmp9-bgN36ZQQrssmCj3923izTRaPCyvWF7CotAh7fVW7yT3CSHKe2wYB90cok2kSkTbhEu3p0t85A client_id =818760124503@developer.gserviceaccount.com authuser=0 hl=en
    • cookie_policy_enforce=false ...您的浏览器会拒绝所有 cookie 吗?
    • 不,我的浏览器不拒绝任何 cookie,一些网站甚至 google 和 facebook 在我的浏览器 (chrome) 中存储 cookie。我也在 Firefox 中尝试过,但发生了同样的事情。
    • 我无法重现您的问题,在我的测试中它直接运行没有任何问题。对不起
    【解决方案2】:

    我遇到了同样的错误,我发现一个问题记录在 https://code.google.com/p/google-apps-script-issues/issues/detail?id=3414。看起来这正在影响目前尝试授权新脚本的许多用户。

    【讨论】:

      【解决方案3】:
      1. 在脚本编辑器中,选择资源 > 使用 Google API....
      2. 单击“Google API 控制台”。链接
      3. 选择 API 和身份验证 > 注册应用
      4. 将您的脚本项目注册为 Web 应用程序
      5. 选择证书 > 生成新密钥

      它对我有用。

      【讨论】:

        猜你喜欢
        • 2013-01-18
        • 2020-07-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-03-05
        • 2018-08-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多