【问题标题】:Apps Scripts OAuth2 authorization using gapi from inside HtmlServiceApps 使用来自 HtmlService 内部的 gapi 编写 OAuth2 授权脚本
【发布时间】:2017-11-05 12:43:27
【问题描述】:

我正在尝试通过在 HtmlService 项目中使用 gapi 库来获得 OAuth2 授权。我从控制台获得了我的 CLIENT_ID,并设置了“授权的 Javascript 起源”,其中包含我能想到的所有内容,例如“https://script.google.com”、“https://script.googleusercontent.com”等,但我总是以“原点不匹配”错误。

这是我在 html javascript 代码中使用的代码。

function checkAuth() {
  gapi.auth.authorize({
    'client_id': CLIENT_ID,
    'scope': SCOPES,
    'immediate': false
  }, handleAuthResult);
}

我做错了什么?

谢谢

【问题讨论】:

  • 您是否仔细检查并遵循了docs 中提到的内容?

标签: javascript google-apps-script oauth-2.0 google-oauth


【解决方案1】:

要获取来源,您需要启动您的 web 应用程序。右键单击并单击Inspect。这应该会打开 Devtools。单击Elements 选项卡。查找 id="sandboxFrame" 的 iframe。您的 webapp 源中的 iframe 的源。它看起来像:

当您将其添加到您的凭据时,只需添加域部分离开端点。

https://n-rilyfaex6q3..iimkn7ufgvlphhi2..l3l73y-0lu-script.googleusercontent.com

【讨论】:

  • n-***-script.googleusercontent.com 我不记得是你添加了 https://
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-06
  • 1970-01-01
  • 2013-03-18
相关资源
最近更新 更多