gpt4 book ai didi

javascript - Google Drive API Picker v3(2018 年 5 月)窗口消失并给出 .split is not a function 错误

转载 作者:行者123 更新时间:2023-11-29 15:15:02 25 4
gpt4 key购买 nike

使用 Google Drive API Picker v3 , Chrome 版本 66.0.3359.139

  1. 每个账号只能登录一次。
  2. 您可以在帐户之间来回切换,但如果您尝试连续访问同一个帐户 2 次...它将失败,并显示 .split 不是一个函数。

当 oauthToken 尝试在客户端解析时似乎有错误。

为什么授权不更新?是否有设置或我缺少的东西?

Chrome 堆栈跟踪:

3723580519-idpiframe.js:26 Uncaught TypeError: (b || "").split is not a function
at Xa (3723580519-idpiframe.js:26)
at 3723580519-idpiframe.js:61
at 3723580519-idpiframe.js:55
at eb.h.getItem (3723580519-idpiframe.js:35)
at Ib.Q.o (3723580519-idpiframe.js:55)
at Ib.o (3723580519-idpiframe.js:61)
at Sb (3723580519-idpiframe.js:68)
at W.h.kb (3723580519-idpiframe.js:76)
at Object.A (3723580519-idpiframe.js:83)
at Jb.Cb (3723580519-idpiframe.js:63)

这是我的代码:

var clientId = 'stuff.apps.googleusercontent.com';
var scope = ['https://www.googleapis.com/auth/drive.readonly'];
var appId = "my-app-id";
var pickerApiLoaded = false;

function loadPicker() { //called when js api loads
gapi.load('auth2', { 'callback': onAuthApiLoad });
gapi.load('picker', { 'callback': onPickerApiLoad });
}

function onAuthApiLoad() {
var authBtn = document.getElementById('accessGoogleDrive');
authBtn.disabled = false;
authBtn.addEventListener('click', function () {
gapi.auth2.authorize({
client_id: clientId,
scope: scope,
//prompt: "consent"
'immediate':false
}, handleAuthResult);
});
}

function onPickerApiLoad() {
pickerApiLoaded = true;
}

function handleAuthResult(authResult) {
console.log("handleAuthResult", authResult);
if (authResult && !authResult.error) {
createPicker(authResult.access_token);
}
}

// Create and render a Picker object for searching images.
function createPicker(oauthToken) {
if (pickerApiLoaded && oauthToken) {
console.log("Creating Picker for Google Drive...");
var view = new google.picker.View(google.picker.ViewId.PDFS);
var picker = new google.picker.PickerBuilder()
.setAppId(appId)
.setOrigin("http://localhost:8080")
.setOAuthToken(oauthToken)
.addView(view)
.setCallback(pickerCallback)
.build();
picker.setVisible(true);
}
}

// A simple callback implementation.
function pickerCallback(data) {
console.log("Successfully picked: ", data);
if (data.action == google.picker.Action.PICKED) {
var fileId = data.docs[0].id;
alert('The user selected: ' + fileId);
}
}

//Google APIs script: "https://apis.google.com/js/api.js?onload=loadPicker"

提前致谢!

最佳答案

改变

var scope = ['https://www.googleapis.com/auth/drive.readonly'];

var scope = 'https://www.googleapis.com/auth/drive.readonly';

根据 https://github.com/google/google-api-javascript-client/issues/13#issuecomment-290129284

关于javascript - Google Drive API Picker v3(2018 年 5 月)窗口消失并给出 .split is not a function 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50123733/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com