Google Drive Api中的Acess_token null

问题描述

我正在尝试使用Javascript更新Google云端硬盘中的文件,但是acess_token返回null。我的文件基于这个问题Google Drive API V3 (javascript) update file contents

const update = () => {
    gapi.load('client:auth2',() =>{
      gapi.client.init({
        apiKey: 'MY API KEY',clientId: '**************.apps.googleusercontent.com',discoveryDocs: ["https://www.googleapis.com/discovery/v1/apis/drive/v3/rest"],scope: 'https://www.googleapis.com/auth/drive',}).then(v => {
        var content = 'Hello World';
        var contentBlob = new  Blob([content],{
          'type': 'text/plain'
        });
        updateFileContent('File id',contentBlob,function(response) {
          console.log(response);
        });
      })
    })


  const updateFileContent = (fileId,callback) => {
    var xhr = new XMLHttpRequest();
    xhr.responseType = 'json';
    xhr.onreadystatechange = function() {
      if (xhr.readyState != XMLHttpRequest.DONE) {
        return;
      }
      callback(xhr.response);
    };
    xhr.open('PATCH','https://www.googleapis.com/upload/drive/v3/files/' + fileId + '?uploadType=media');
    xhr.setRequestHeader('Authorization','Bearer ' + gapi.auth.getToken().access_token);
    xhr.send(contentBlob);
  }

有人知道我在做什么错吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)