Google Drive API Picker v3(2018年5月)窗口消失并显示.​​split不是函数错误 [英] Google Drive API Picker v3 (May 2018) window disappears and gives .split is not a function error

查看:65
本文介绍了Google Drive API Picker v3(2018年5月)窗口消失并显示.​​split不是函数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Google云端硬盘API选择器v3 ,Chrome版本66.0.3359.139

Using Google Drive API Picker v3, Chrome Version 66.0.3359.139

  1. 每个帐户只能一次登录一次.
  2. 您可以在两个帐户之间来回切换,但是如果您尝试连续两次访问同一帐户...它将失败,因为.split不是一个功能.

尝试在客户端上重新解析oauthToken时似乎出现错误.

为什么认证不更新?有设置或我缺少的东西吗?

There seems to be an error when the oauthToken attempts to be parsed back on the client side.

Why is the auth not updating? Is there a setting or something I am missing?

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"

感谢!

THANKS IN ADVANCE!

推荐答案

更改

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

这篇关于Google Drive API Picker v3(2018年5月)窗口消失并显示.​​split不是函数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆