2017-07-18 63 views
0

我想从用户谷歌驱动器下载spreadhseets。我遇到了CORS问题。谷歌驱动器:gsheets通过REST API下载

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:无法提取响应:没有合适的HttpMessageConverter发现响应类型[接口java.sql.Blob中]和内容类型[应用程序/ vnd.openxmlformats-officedocument.spreadsheetml.sheet]

任何帮助非常感谢。

回答

0

至于CORS去,这是相关的导游,我可以找到,How to use CORS to access Google APIs

使用XMLHttpRequest2使 CORS请求。

对Google API的CORS请求类似于REST请求。用于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'); 

请求头被添加到使用 XMLHttpRequest.setRequestHeader该请求。

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

您可以通过在加载时添加事件侦听器和 错误事件来注册回调。点击此链接了解有关XMLHttpRequest的信息 事件

另请确保您有权从其他用户下载电子表格文件 。