【问题标题】:Google Drive : gsheets download through REST APIGoogle Drive:通过 REST API 下载 gsheets
【发布时间】:2017-07-18 01:23:08
【问题描述】:

我正在尝试从用户的谷歌驱动器下载电子表格。我遇到了 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] 和内容类型 [application/vnd.openxmlformats-officedocument.spreadsheetml.sheet] 找到合适的 HttpMessageConverter /p>

非常感谢任何帮助。

【问题讨论】:

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


    【解决方案1】:

    就 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 的信息 事件

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-02
      • 1970-01-01
      • 2020-06-21
      • 2020-02-05
      • 1970-01-01
      相关资源
      最近更新 更多