2017-06-04 58 views
1

我试图通过使用来自HtmlService项目内部的gapi库进行OAuth2授权。我已经从控制台获得了我的CLIENT_ID,并且我已经设置了“授权的Javascript起源”,包含我可以想到的所有内容,例如“https://script.google.com”,“https://script.googleusercontent.com”等,但我总是以“起源不匹配”错误。Apps脚本使用来自HtmlService内部的gapi的OAuth2授权

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

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

我在做什么错?

谢谢

+0

你有双重检查,并遵循什么在[文件]中提及(https://developers.google.com/apps-script/guides/rest/quickstart/js#troubleshooting )? –

回答

1

要得到您需要启动您的web应用程序的起源。点击右键并点击Inspect。这应该会打开Devtools。点击Elements标签。寻找id =“sandboxFrame”的iframe。源代码中的iframe来源于您的webapp。它看起来像:

webapp origin as seeen in devtools

当你将它添加到您的凭据只是添加域部分离开过终点。

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

+0

那么你的意思是只添加https://googleusercontent.com? – mclzc

+0

n - *** - script.googleusercontent.com关闭我的头顶我不记得是你添加https:// –

+0

它的工作。谢谢!! – mclzc