0

I want to get content of publicly shared google docs using axios if possible. I can get a google sheet content with a Google API key using the following code.

const url = "https://sheets.googleapis.com/v4/spreadsheets/{SHEET_ID}/?key={API_KEY}&includeGridData=true";
axios.get(url)
    .then(res => {
         // Something
});

I tried the same for getting google docs by the following URL but it does not work. https://docs.googleapis.com/v1/documents/{DOC_ID}/?key={API_KEY}

Is it possible like this?

S___
  • 3
  • 3
  • It seems that in the current stage, Google Docs API cannot be used with API key. So is this workaround useful for your situation? https://stackoverflow.com/q/61399708 – Tanaike Feb 07 '21 at 08:47
  • @Tanaike are you sure? This is quoted from the [Google Doc API official page](https://developers.google.com/docs/api/how-tos/authorizing) If the request doesn't require authorization (such as a request for public data), then the application must provide either the API key or an OAuth 2.0 token, or both—whatever option is most convenient for you. – S___ Feb 07 '21 at 08:55
  • Thank you for replying. I deeply apologize my comment was not useful for your situation. – Tanaike Feb 07 '21 at 08:57
  • @Tanaike you were correct. That API does not work with an API key only although it is supposed to. I probably need to use a workaround. – S___ Feb 07 '21 at 10:48

1 Answers1

0

After some digging around, I found out that Google Doc API is supposed to work with only API key for public data using a GET request according to the documentation. But as of now, it returns 401 error if an OAuth 2 access token is missing. There is an open issue regarding that here.

S___
  • 3
  • 3