我在调用 Google api 的 chrome 扩展程序的后台页面中运行了 javascript 代码。下面的代码本质上是请求 oAuth2 令牌。
function init(){
gapi.client.setApiKey(apiKey);
console.log("Initializing...");
gapi.auth.init(function() { setTimeout(authenticate,100)});
}
function authenticate(){
console.log("Initialized. Now AUthenticating");
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: false},api);
}
身份验证窗口按预期打开,但是在用户登录并允许我的应用程序后,页面只是冻结。回调 (api()) 从未进行过,我也没有收到令牌。是因为我从后台页面调用它而身份验证窗口无法发送回响应吗?
如果是,解决方法/解决方案是什么?
如果是这样,我该如何解决这个问题?