[問題] Google驗證有時可以有時不行

看板Web_Design作者 (watching you)時間8年前 (2017/06/14 16:32), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
小弟想要製作一個按鈕,當按下按鈕後會跳出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://www.ptt.cc/bbs/Web_Design/M.1497429138.A.AC6.html
文章代碼(AID): #1PGFIIh6 (Web_Design)
文章代碼(AID): #1PGFIIh6 (Web_Design)