I have created an app (React Native) where I am required to show the responses of a google form, so I created the Responses Sheet.
Though Sheets API would be the best sol
I believe your goal as follows.
When Google Spreadsheet is used with Sheets API, the access token and the API key are required to be used. When you want to retrieve the values from Google Spreadsheet without using the access token and the API key, in this answer, I would like to propose the following workaround using Web Apps created by Google Apps Script. The flow of this workaround is as follows.
Please do the following flow.
Sample script of Web Apps is a Google Apps Script. So please create a project of Google Apps Script.
If you want to directly create it, please access to https://script.new/. In this case, if you are not logged in Google, the log in screen is opened. So please log in to Google. By this, the script editor of Google Apps Script is opened.
Please copy and paste the following script (Google Apps Script) to the script editor. This script is for the Web Apps.
function doGet(e) {
const id = e.parameter.spreadsheetId;
const sheetName = e.parameter.sheetName;
const sheet = SpreadsheetApp.openById(id).getSheetByName(sheetName);
const values = sheet.getDataRange().getValues();
return ContentService.createTextOutput(JSON.stringify({values: values})).setMimeType(ContentService.MimeType.JSON);
}
https://www.googleapis.com/auth/drive.readonly
and https://www.googleapis.com/auth/drive
to the access token. These scopes are required to access to Web Apps.https://script.google.com/macros/s/###/exec
.
You can retrieve the values from Google Spreadsheet using the following script.
const baseUrl = "https://script.google.com/macros/s/###/exec"; // Please set your Web Apps URL.
const para = {
spreadsheetId: "###", // Please set your Google Spreadsheet ID.
sheetName: "Sheet1" // Please set the sheet name you want to retrieve the values.
};
const q = new URLSearchParams(para);
const url = baseUrl + "?" + q;
fetch(url)
.then(res => res.json())
.then(res => {
const values = res.values;
console.log(values);
});
If you want to test the above Web Apps using a curl command, you can also use the following curl command.
$ curl -L "https://script.google.com/macros/s/###/exec?spreadsheetId=###&sheetName=Sheet1"