问题描述
我正在尝试通过HtmlService项目内部的gapi库进行OAuth2授权.我从控制台获取了CLIENT_ID,并设置了"Authorized Javascript Origins"(授权的Javascript起源),其中包含了所有我可以想到的内容,例如" https://script.google.com "," https://script.googleusercontent.com ",等等,但我总是以来源不匹配"错误结束.
I'm trying to be OAuth2-authorized by using the gapi library from inside an HtmlService project. I've got my CLIENT_ID from the console and I've set up the "Authorized Javascript Origins" with all of what I could think about like "https://script.google.com", "https://script.googleusercontent.com", etc, but I always end with an "origin mismatch" error.
这是我从html javascript代码内部使用的代码.
This is the code I'm using from inside the html javascript code.
function checkAuth() {
gapi.auth.authorize({
'client_id': CLIENT_ID,
'scope': SCOPES,
'immediate': false
}, handleAuthResult);
}
我在做什么错了?
谢谢
推荐答案
要获取来源,您需要启动Webapp.右键单击并单击Inspect
.这应该打开Devtools.单击Elements
选项卡.查找ID为"sandboxFrame"的iframe.源在您的Web应用程序源中的iframe.它看起来像:
To get the origin you need launch your webapp. Right click and click Inspect
. This should open Devtools. Click on the Elements
tab. Look for the iframe with the id="sandboxFrame". The source the that iframe in your webapp origin. It will look like:
将其添加到凭据中时,只需添加不包含端点的域部分.
When you add it to your credentials just add the domain part leaving off the endpoint.
这篇关于HtmlService内部使用gapi的Apps脚本OAuth2授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!