作者qazsd (watching you)
看板Web_Design
标题[问题] Google验证有时可以有时不行
时间Wed Jun 14 16:32:14 2017
小弟想要制作一个按钮,当按下按钮後会跳出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
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 59.124.165.66
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Web_Design/M.1497429138.A.AC6.html