我正在研究通过OAuth2连接到第三方服务的GMail加载项。要获取授权代码,请使用以下重定向URI: https://script.google.com/macros/d/[SCRIPT_ID]/usercallback 。 这是触发授权的代码段:
var statetoken = ScriptApp.newstatetoken()
.withMethod( "authCallback" )
.withTimeout( 120 )
.createToken();
var authUrl = _authBaseUrl
+ "&client_id=" + encodeURIComponent( _clientId )
+ "&redirect_uri=" + encodeURIComponent( _redirecturi )
+ "&state=" + statetoken;
CardService.newAuthorizationException()
.setauthorizationUrl( authUrl )
.setResourceDisplayName( "Resource" )
.throwException();
这是回调函数(HTML代码段摘自here):
function authCallback( request )
{
createaccessToken( request.parameter.code );
return HtmlService.createHtmlOutput('Success! <script>setTimeout(function() { top.window.close() },1);</script>');
}
createaccessToken 函数被成功调用,附加组件获得访问令牌。但是,HTML不在弹出窗口中提供。而是有一个占位符,出现以下错误:“脚本已完成,但未返回任何内容。”
结果,我陷入了一个错误窗口,该窗口无法自动关闭,并且不会告诉用户必须关闭该窗口才能继续使用附件。
我做错什么了吗,或者这是某种错误或已删除的功能?感谢您的任何建议。
UPD: 错误看起来像这样