簡體   English   中英

將 Google 電子表格 API V4 (spreadsheets.values.get) 與 Private Sheets 連接起來

[英]Connect Google Spreadsheets API V4 (spreadsheets.values.get) with Private Sheets

請求:我需要使用 JS 將服務與私人 Google 表格連接起來。 不需要讓最終用戶登錄 Google 帳戶,我只需要將私人 Google 表格中的一些數據顯示到 Web 頁面中。

我已經有一個密鑰和一個客戶 ID,我按照這些步驟使用https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/get

到目前為止,它的工作原理,我的請求的問題是這個示例讓最終用戶登錄到谷歌帳戶,然后進行 Api 呼叫。

注意:如果 Google 表格可以通過鏈接共享,那么我可以使用密鑰連接,但是 Google 表格應該是私有的,僅授予某些人訪問權限。

有沒有辦法只使用私人 Google 表格中的數據而不讓最終用戶登錄 Google 帳戶?

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可以訪問應用程序”設置為“任何人,甚至匿名”,並且選項“執行為”設置為“我”,因此它可以在您的憑據下運行。 一個簡單的 web 應用程序示例如下:

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);
}

這將從“A2:E6”范圍內檢索值作為字符串。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM