我在 chrome 扩展中使用gapi客户端来访问 Google Drive。第一步是授权我的应用程序。我正在使用 gapi.auth.authorize 来启动授权。在我通过 gapi 启动的弹出窗口授权应用程序后,窗口永远不会关闭并卡住,如下图所示。但是后台授权已经成功,因为如果我手动关闭窗口,下次我就看不到卡住的弹出窗口了。有人能指出我做错了什么吗?
在授权弹出窗口上单击“允许访问”后,
然后它显示一个空白弹出窗口,它被卡住了
我正在使用的代码
function handleClientLoad(){
gapi.client.setApiKey('My API key');
window.setTimeout(checkAuthAuto, 1);
}
var checkAuthAuto = function () {
console.log('checkAuthAuto');
gapi.auth.authorize({
client_id: 'My client id',
scope: 'https://www.googleapis.com/auth/drive.file',
immediate: true
}, handleAuthResult);
}
function handleAuthResult(authResult) {
console.log('handleAuthResult');
var authButton = document.getElementById('authorizeButton');
var filePicker = document.getElementById('filePicker');
var addButton = document.getElementById('addButton');
authButton.style.display = 'none';
filePicker.style.display = 'none';
addButton.style.display = 'none';
if (authResult && !authResult.error) {
addButton.style.display = 'block';
addButton.onclick = uploadFile;
console.log('handleAuthResult:noerror');
} else {
// No access token could be retrieved, show the button to start the authorization flow.
authButton.style.display = 'block';
console.log('handleAuthResult:error');
console.log(authResult);
authButton.onclick = function() {
console.log('authButton.onclick');
gapi.client.setApiKey('My api key');
gapi.auth.authorize({
client_id: 'My client id',
scope: 'https://www.googleapis.com/auth/drive.file',
immediate: false
}, handleAuthResult);
return false;
};
}
}