Reputation: 520
Request: I need to Connect a Service using JS with a Private Google Sheet. It's not needed to get the end user to sign in into a Google Account, I only need to show some data from that Private Google Sheet into the Web page.
I already have a Key and a Client ID which I use following these steps https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/get
It works so far, the issue that I have with my request is that this sample get the end user to sign in into a Google account to then make the Api Call.
NOTE: if the Google Sheet is Shareable by a link then I can connect with the Key, however the Google Sheet should be private to only grant access to some people.
Is there a way to only consume the data from the Private Google Sheet without to get the end user sign in into the Google Account?
Upvotes: 1
Views: 880
Reputation: 3350
As suggested in the comments, you can use a Web App as an API to make a get or post request from your JavaScript application, in order to not need credentials/token for those requests you need to deploy the web app with the option "who has acces to the app" set to "anyone, even anonymous" and the option "Execute as" set to "me" so it can be run under your credentials. An example of a simple web app to which you can do a get request to the deployed url is below:
function doGet() {
var spreadsheet = SpreadsheetApp.openById("[SPREADSHEET-ID]");
var sheet = spreadsheet.getSheetByName("Sheet1");
var values = sheet.getRange("A2:E6").getValues();
var stringOutput = values.toString();
return ContentService.createTextOutput(stringOutput);
}
This will retrieve the values from the "A2:E6" range as a string.
Upvotes: 1