0
votes

I am trying to download spreadhseets from a users google drive. I am encountering a CORS issue.

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

I am trying to make a GET request on the server side. I tried using restTemplate.exchange but I am not sure what format my response should be in. Basically completely lost.

Is there a way to make the GET to pull the file and pass back to my front end?

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]

Any help greatly appreciated.

1

1 Answers

0
votes

As far as CORS goes, this is the relevant guide I can find, How to use CORS to access Google APIs

Use XMLHttpRequest2 to make CORS requests.

A CORS request to a Google API is similar to a REST request. The URL for a CORS request follows this pattern:

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.

The request body is sent using the XMLHttpRequest.send method.

You can register callbacks by adding event listeners on the load and error events. Follow this link for information about XMLHttpRequest events

Also make sure you have permission to download the spreadsheet file from the other user.