简体   繁体   English

Google云端硬盘:通过REST API下载gsheets

[英]Google Drive : gsheets download through REST API

I am trying to download spreadhseets from a users google drive. 我正在尝试从用户的Google驱动器下载Spreadseets。 I am encountering a CORS issue. 我遇到了CORS问题。

http://javascript.wekeepcoding.com/article/15417055/CORS+on+exportLinks+for+Google+Docs+spreadsheets+not+working http://javascript.wekeepcoding.com/article/15417055/CORS+on+exportLinks+for+Google+Docs+spreadsheets+not+working

Reading this: 阅读此:

https://github.com/google/google-api-javascript-client/issues/47 https://github.com/google/google-api-javascript-client/issues/47

I am trying to make a GET request on the server side. 我正在尝试在服务器端发出GET请求。 I tried using restTemplate.exchange but I am not sure what format my response should be in. Basically completely lost. 我尝试使用restTemplate.exchange,但不确定我的响应应采用哪种格式。基本上完全丢失了。

Is there a way to make the GET to pull the file and pass back to my front end? 有没有办法让GET提取文件并传递回我的前端?

I keep getting this error for whatever format I try: 无论尝试哪种格式,我都会不断收到此错误:

org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [interface java.sql.Blob] and content type [application/vnd.openxmlformats-officedocument.spreadsheetml.sheet] org.springframework.web.client.RestClientException:无法提取响应:未为响应类型[接口java.sql.Blob]和内容类型[application / vnd.openxmlformats-officedocument.spreadsheetml.sheet]找到合适的HttpMessageConverter。

Any help greatly appreciated. 任何帮助,不胜感激。

As far as CORS goes, this is the relevant guide I can find, How to use CORS to access Google APIs 就CORS而言,这是我可以找到的相关指南,即如何使用CORS访问Google API

Use XMLHttpRequest2 to make CORS requests. 使用XMLHttpRequest2发出CORS请求。

A CORS request to a Google API is similar to a REST request. 向Google API发送的CORS请求类似于REST请求。 The URL for a CORS request follows this pattern: CORS请求的URL遵循以下格式:

https://www.googleapis.com +
  REST path + URL Params
Example: here is a REST request:

var restRequest = gapi.client.request({
  'path': 'https://people.googleapis.com/v1/people/me/connections',
  'params': {'sortOrder': 'LAST_NAME_ASCENDING'}
});
And here is the equivalent CORS request:

var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://people.googleapis.com/v1/people/me/connections?sortOrder=LAST_NAME_ASCENDING');

Request headers are added to the request using XMLHttpRequest.setRequestHeader. 使用XMLHttpRequest.setRequestHeader将请求标头添加到请求中。

The request body is sent using the XMLHttpRequest.send method. 使用XMLHttpRequest.send方法发送请求正文。

You can register callbacks by adding event listeners on the load and error events. 您可以通过在load和error事件上添加事件侦听器来注册回调。 Follow this link for information about XMLHttpRequest events 单击此链接以获取有关XMLHttpRequest事件的信息

Also make sure you have permission to download the spreadsheet file from the other user. 另外,请确保您有权从其他用户下载电子表格文件。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM