Google验证JS API正在重定向到错误的URL



我已经使用下面的代码几年了,直到一个月前它还可以正常工作。

MY_CUSTOM_URL在Google授权重定向URI上声明和注册。

function initClient() {   
gapi.client.init({
apiKey: APKEY,
clientId: CLIENTID,
discoveryDocs: ["https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest"],
scope: "https://www.googleapis.com/auth/calendar",
redirect_uri: MY_CUSTOM_URL,
ux_mode: 'redirect',                
}).then(function () {                    
gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);                        
updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
});
}

当我尝试调用gapi.auth2.getAuthInstance().signIn();时,它会忽略MY_CUSTOM_URL并重定向到默认的网站根域,即使我使用的是localhost(它也在谷歌上注册(,也不会进行身份验证。

如果我评论ux_mode,它会打开弹出窗口并正常工作,但我不能为此使用弹出窗口。

谢谢

来自Doc

必需。确定API服务器在用户完成授权流程值必须完全匹配API中为您的项目列出的redirect_uri值之一控制台。请注意,http或https方案、大小写和尾部斜杠("/"(必须全部匹配。

在API控制台中检查redirect_uri,使其与您的MY_CUSTOM_URL相匹配

这是

select api=>credentials=>select OAuth 2.0客户端ID=>授权重定向URI[输入字段]

最新更新