我正在使用我的网络应用程序中的Google云端硬盘选择器。一切正常但是当它打开一个验证窗口并且我批准它时,窗口会自动关闭而不显示或允许文件选择。
这是我的JavaScript代码:
//从Google API控制台获取的浏览器API密钥。 var developerKey ='*****************************';
// The Client ID obtained from the Google API Console. Replace with your own Client ID.
var clientId = '*********-k826p6sl1qkhpnrtbbi0jktboijupvf9.apps.googleusercontent.com';
// Scope to use to access user's photos.
var scope = 'https://www.googleapis.com/auth/drive.readonly';
var pickerApiLoaded = false;
var oauthToken;
// Use the API Loader script to load google.picker and gapi.auth.
function onApiLoad() {
gapi.load('auth2', onAuthApiLoad);
gapi.load('picker', onPickerApiLoad);
}
function onAuthApiLoad() {
var authBtn = document.getElementById('GoogleDrive');
authBtn.disabled = false;
authBtn.addEventListener('click', function () {
gapi.auth2.authorize({
client_id: clientId,
scope: scope
}, handleAuthResult);
});
}
function onPickerApiLoad() {
pickerApiLoaded = true;
createPicker();
}
function handleAuthResult(authResult) {
if (authResult && !authResult.error) {
oauthToken = authResult.access_token;
createPicker();
}
}
// Create and render a Picker object for picking user Photos.
function createPicker() {
if (pickerApiLoaded && oauthToken) {
var picker = new google.picker.PickerBuilder().
addView(google.picker.ViewId.PHOTOS).
setOAuthToken(oauthToken).
setDeveloperKey(developerKey).
setCallback(pickerCallback).
build();
picker.setVisible(true);
}
}
// A simple callback implementation.
function pickerCallback(data) {
var url = 'nothing';
if (data[google.picker.Response.ACTION] == google.picker.Action.PICKED) {
var doc = data[google.picker.Response.DOCUMENTS][0];
url = doc[google.picker.Document.URL];
}
var message = 'You picked: ' + url;
document.getElementById('result').innerHTML = message;
}
我使用以下参考:
<script type="text/javascript" src="https://apis.google.com/js/api.js?onload=onApiLoad"></script>
任何人都可以帮助我吗?提前谢谢。