[问题] Google验证有时可以有时不行

楼主: qazsd ( )   2017-06-14 16:32:14
小弟想要制作一个按钮,当按下按钮后会跳出Google Account的验证视窗
接着选取帐号后,会跳出Google Picker供选取该帐号的Google Drive档案
程式码如下:
<script type="text/javascript">
var developerKey = '1111111111111';
var clientId = "22222222222"
var scope = ['https://www.googleapis.com/auth/photos'];
var pickerApiLoaded = false;
var oauthToken;
//Use the API Loader script to load google.picker and gapi.auth.
function onApiLoad() {
console.log("onApiLoad");
gapi.load('auth2', {
'callback': onAuthApiLoad
});
gapi.load('picker', {
'callback': onPickerApiLoad
});
}
function onAuthApiLoad() {
console.log("onAuthApiLoad");
window.gapi.auth2.authorize({
'client_id': clientId,
'scope': scope,
'immediate': true //True:Popup window everytime; False:No popup window
}, handleAuthResult);
}
function onPickerApiLoad() {
console.log("onPickerApiLoad");
pickerApiLoaded = true;
createPicker();
}
function handleAuthResult(authResult) {
console.log("handleAuthResult");
if (authResult && !authResult.error) {
oauthToken = authResult.access_token;
createPicker();
}
}
// Create and render a Picker object for picking user Photos.
function createPicker() {
console.log("createPicker");
if (pickerApiLoaded && oauthToken) {
var picker = new google.picker.PickerBuilder()
addView(
new google.picker.DocsView()
.setIncludeFolders(true))
.setOAuthToken(oauthToken).setDeveloperKey(developerKey)
.setCallback(pickerCallback).build();
picker.setVisible(true);
}
}
<body>
<input id="search" type="button" value="Button" onclick="onApiLoad()"/>
</body>
但是当按下按钮后,有跳出选取帐号的视窗,
选完视窗后,有时第一次可以成功跳出Picker,
但再次按下按钮后,就不会跳出Picker了,而那时console的讯息如下:
Uncaught TypeError: (b || "").split is not a function
想请教要怎么修改才能每次按下按钮都能成功叫出Picker?
先谢谢各位大大了! m(_ _)m

Links booklink

Contact Us: admin [ a t ] ucptt.com