使用javascript api从我们的网站页面上传Google驱动器帐户中的文件

使用javascript api从我们的网站页面上传Google驱动器帐户中的文件,javascript,google-api,google-drive-api,Javascript,Google Api,Google Drive Api,我正试图上传文件到我的谷歌驱动器帐户使用网页形式。我选择了一个文件,我必须使用JavaScript API将其上传到我的谷歌硬盘,所以,如果有任何解决方案需要,请有人帮助我 这里是一个访问谷歌驱动器的示例代码,但我无法获得上传文件的代码 <!--Add a button for the user to click to initiate auth sequence --> <button id="authorize-button" style="visibility: hidd

我正试图上传文件到我的谷歌驱动器帐户使用网页形式。我选择了一个文件,我必须使用JavaScript API将其上传到我的谷歌硬盘,所以,如果有任何解决方案需要,请有人帮助我

这里是一个访问谷歌驱动器的示例代码,但我无法获得上传文件的代码

<!--Add a button for the user to click to initiate auth sequence -->
<button id="authorize-button" style="visibility: hidden">Authorize</button>
<script type="text/javascript">
  var clientId = '######';
  var apiKey = 'aaaaaaaaaaaaaaaaaaa';
  // To enter one or more authentication scopes, refer to the documentation for the API.
  var scopes = "https://www.googleapis.com/auth/drive";

  // Use a button to handle authentication the first time.
  function handleClientLoad() {
    gapi.client.setApiKey(apiKey);
    window.setTimeout(checkAuth,1);
  }

  function checkAuth() {
    gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true}, handleAuthResult);
  }

  function handleAuthResult(authResult) {
    var authorizeButton = document.getElementById('authorize-button');
    if (authResult && !authResult.error) {
      authorizeButton.style.visibility = 'hidden';
      makeApiCall();
    } else {
      authorizeButton.style.visibility = '';
      authorizeButton.onclick = handleAuthClick;
    }
  }

  function handleAuthClick(event) {
    gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: false}, handleAuthResult);
    return false;
  }

  // Load the API and make an API call.  Display the results on the screen.
  function makeApiCall() {
    gapi.client.load('drive', 'v2', function() {

      var request = gapi.client.drive.files.list ( {'maxResults': 5 } );

      request.execute(function(resp) {          
        for (i=0; i<resp.items.length; i++) {
                var titulo = resp.items[i].title;
                var fechaUpd = resp.items[i].modifiedDate;
                var userUpd = resp.items[i].lastModifyingUserName;

                var fileInfo = document.createElement('li');
                fileInfo.appendChild(document.createTextNode('TITLE: ' + titulo + ' - LAST MODIF: ' + fechaUpd + ' - BY: ' + userUpd ));                
                document.getElementById('content').appendChild(fileInfo);
        }
      });        
    });
  }
</script>
<script src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>    
<p><b>These are 5 files from your GDrive :)</b></p>
<div id="content"></div>

我假设您已经在:console.developers.google.com下创建了一个项目,并授权了API?你能包括你收到的错误吗?你好,实际上我想实现新的API,用于将文件从我的网站上传到Google drive。因此,如果你有任何解决方案,请在这里发布。