简体   繁体   English

我是否需要提交以下Google驱动器范围的验证请求,才能从选择器中下载文件?

[英]Do i require to Submit a verfication request for the following google drive scopes in order to download a file from picker?

Do i require to Submit a verification request for the following google drive scopes in order to download a file from picker? 我是否需要提交以下Google驱动器范围的验证请求,才能从选择器中下载文件?

  • googleapis.com/auth/drive googleapis.com/auth/drive
  • www.googleapis.com/auth/drive.readonly www.googleapis.com/auth/drive.readonly

The picker doesn't load due to the following error 由于出现以下错误,选择器无法加载

错误:invalid_sope

My objective is to download a file from google drive to our website. 我的目标是从Google Drive下载文件到我们的网站。

The picker loads when i use drive.file, but when i try to download the file i get a 404 file not found error. 当我使用drive.file时,选择器会加载,但是当我尝试下载文件时,会出现404文件未找到错误。

using the google drive reference files/get on there site i can simulate the 404 but if i change the scope to using just drive or drive.readonly i get a 200 status which is what i'm after but the picker does not load. 使用谷歌驱动器参考文件/在那里获得网站,我可以模拟404,但如果我将范围更改为仅使用drive或drive.readonly,我将得到200状态,这是我要的状态,但选择器无法加载。

Is there a way around this without having to submit a verification request form? 有没有解决此问题的方法而不必提交验证请求表?

The code i'm using is based of google drive sample code. 我使用的代码基于Google Drive示例代码。

 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title>Google Picker Example</title> <script type="text/javascript"> // The Browser API key obtained from the Google Developers Console. var developerKey = ''; // The Client ID obtained from the Google Developers Console. Replace with your own Client ID. var clientId = "" // Scope to use to access user's photos. var scope = ['https://www.googleapis.com/auth/drive']; var pickerApiLoaded = false; var oauthToken; // Use the API Loader script to load google.picker and gapi.auth. function onApiLoad() { gapi.load('auth', {'callback': onAuthApiLoad}); gapi.load('picker', {'callback': onPickerApiLoad}); } function onAuthApiLoad() { window.gapi.auth.authorize( { 'client_id': clientId, 'scope': scope, 'immediate': false }, handleAuthResult); } function onPickerApiLoad() { pickerApiLoaded = true; createPicker(); } function handleAuthResult(authResult) { if (authResult && !authResult.error) { oauthToken = authResult.access_token; createPicker(); } } // Create and render a Picker object for picking user Photos. function createPicker() { var view = new google.picker.DocsView(); view.setIncludeFolders(true); if (pickerApiLoaded && oauthToken) { var picker = new google.picker.PickerBuilder(). addView(view). setOAuthToken(oauthToken). setDeveloperKey(developerKey). setCallback(pickerCallback). build(); picker.setVisible(true); } } // A simple callback implementation. function pickerCallback(data) { debugger; var url = 'nothing'; var id = ""; if (data[google.picker.Response.ACTION] == google.picker.Action.PICKED) { var doc = data[google.picker.Response.DOCUMENTS][0]; url = doc[google.picker.Document.URL]; id = doc[google.picker.Document.ID]; } var accessToken = gapi.auth.getToken().access_token; var xhr = new XMLHttpRequest(); var url = "https://www.googleapis.com/drive/v3/files/" + id + "?alt=media"; xhr.open('GET', url); xhr.setRequestHeader('Authorization', 'Bearer ' + accessToken); xhr.send(); //var message = 'You picked: ' + url; //document.getElementById('result').innerHTML = message; } </script> </head> <body> <div id="result"></div> <!-- The Google API Loader script. --> <script type="text/javascript" src="https://apis.google.com/js/api.js?onload=onApiLoad"></script> </body> </html> 

First, I suggest using the https://www.googleapis.com/auth/drive to have full scope. 首先,我建议使用https://www.googleapis.com/auth/drive来具有完整范围。 Then, show us what the code, how are you doing it? 然后,向我们展示代码,您如何做?

You didn't set the scope in the variable picker 您没有在变量选择器中设置范围

      var picker = new google.picker.PickerBuilder().
          addView(view).
          addView(google.picker.ViewId.DOCS).//<== add this

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Node.js-通过请求从Google云端硬盘下载文件 - Node.js - Download File from Google Drive via request 通过选择器下载的Google云端硬盘文件始终返回未找到的文件 - Google Drive File Download Through Picker Always Returns File Not Found 如何下载我从Google Picker API中选择的文件? - How to download a file that I have chosen from Google Picker API? 从Rails中的Google Picker API下载文件 - Download file from Google Picker API in rails 选择特定文件后,如何停止Google Drive Picker UI自动关闭? - How do I stop the Google Drive Picker UI to close automatically after choosing particular file? 如何使用Google Picker使用“drive.file”范围访问文件? - How do I use Google Picker to access files using the “drive.file” scope? 如何使用JavaScript在Google Picker中下载Google表格? - How do I download a Google Sheet with Google Picker all in JavaScript? Google 云端硬盘文件选择器被谷歌阻止 - Google Drive file picker is blocked by google 当我在 React Native 中下载已上传到 Google Drive 的文件时,我得到的文件大小与原始文件不同 - I get different file size from the original file when I download a file that I have uploaded to Google Drive in React Native 使用javascript和mvc3从Google驱动器下载文件 - Download file from google drive using javascript and mvc3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM