Skip to content

Instantly share code, notes, and snippets.

@tanaikech
Created December 16, 2022 01:39
Show Gist options
  • Save tanaikech/aeb1a21e1e51a902f903e6363cd1a5db to your computer and use it in GitHub Desktop.
Save tanaikech/aeb1a21e1e51a902f903e6363cd1a5db to your computer and use it in GitHub Desktop.
Retrieving Values from Publicly Shared Google Spreadsheet using API key with Javascript

Retrieving Values from Publicly Shared Google Spreadsheet using API key with Javascript

This is a sample script for retrieving the values from a publicly shared Google Spreadsheet using an API key with Javascript.

Sample script

In this sample script, googleapis for Javascript is used.

<script async defer src="https://apis.google.com/js/api.js" onload="handleClientLoad()"></script>
<script>
function handleClientLoad() {
  const apiKey = "###"; // Please set your API key.
  const spreadsheetId = "###"; // Please set your Spreadsheet ID.

  gapi.load('client', async () => {
    await gapi.client.init({ apiKey, discoveryDocs: ["https://sheets.googleapis.com/$discovery/rest?version=v4"] });
    const { result } = await gapi.client.sheets.spreadsheets.values.get({ spreadsheetId, range: "Sheet1" });
    console.log(result);
  });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment