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

时间:2017-07-18 01:23:08

标签: java rest google-api google-drive-api

我正在尝试从用户google驱动器下载spreadhseets。我遇到了一个CORS问题。

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

读这个:

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

我正在尝试在服务器端发出GET请求。我尝试使用restTemplate.exchange,但我不确定我的响应应该是什么格式。基本上完全丢失了。

有没有办法让GET拉出文件并传回我的前端?

无论我尝试何种格式,我都会收到此错误:

org.springframework.web.client.RestClientException:无法提取响应:没有为响应类型[interface java.sql.Blob]找到合适的HttpMessageConverter,内容类型为[application / vnd.openxmlformats-officedocument.spreadsheetml.sheet] < / p>

任何帮助非常感谢。

1 个答案:

答案 0 :(得分:0)

就CORS而言,这是我能找到的相关指南How to use CORS to access Google APIs

  

使用XMLHttpRequest2制作   CORS请求。

     

对Google API的CORS请求类似于REST请求。网址   对于CORS请求,遵循以下模式:

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');
  

使用请求标头添加到请求中   XMLHttpRequest.setRequestHeader。

     

使用XMLHttpRequest.send方法发送请求正文。

     

您可以通过在加载和上添加事件侦听器来注册回调   错误事件。有关XMLHttpRequest的信息,请访问此链接   事件

     

还要确保您有权下载电子表格文件   来自其他用户。

相关问题