Stay organized with collections
Save and categorize content based on your preferences.
Quickstarts explain how to set up and run an app that calls a
Google Workspace API.
Google Workspace quickstarts use the API client libraries to handle some
details of the authentication and authorization flow. We recommend that
you use the client libraries for your own apps. This quickstart uses a
simplified authentication approach that is appropriate for a testing
environment. For a production environment, we recommend learning about
authentication and authorization
before
choosing the access credentials
that are appropriate for your app.
Create a
Google Apps Script
that makes requests to the Google Sheets API.
/** * Creates a Sheets API service object and prints the names and majors of * students in a sample spreadsheet: * https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/get */functionlogNamesAndMajors(){constspreadsheetId='1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms';constrangeName='ClassData!A2:E';try{// Get the values from the spreadsheet using spreadsheetId and range.constvalues=Sheets.Spreadsheets.Values.get(spreadsheetId,rangeName).values;// Print the values from spreadsheet if values are available.if(!values){console.log('Nodatafound.');return;}console.log('Name,Major:');for(constrowinvalues){// Print columns A and E, which correspond to indices 0 and 4.console.log('-%s,%s',values[row][0],values[row][4]);}}catch(err){// TODO (developer) - Handle Values.get() exception from Sheet APIconsole.log(err.message);}}
Click Save .
Click Untitled project, type
Quickstart, and click Rename.
Configure the script
Enable the Google Sheets API
Open the Apps Script project.
Click Editorcode.
Next to Services, click Add a service
add .
Select
Sheets API
and click Add.
Run the sample
In the Apps Script editor, click Run.
The first time you run the sample, it prompts you to authorize access:
Click Review permissions.
Choose an account.
Click Allow.
The script's execution log appears at the bottom of the window.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-14 UTC."],[[["This quickstart demonstrates how to use Google Apps Script to connect to and retrieve data from the Google Sheets API."],["You will need a Google Account and access to Google Drive to complete the setup."],["The process involves creating a script, enabling the Google Sheets API, and authorizing access for the script to interact with your spreadsheets."],["Upon successful execution, the script will print data from a sample spreadsheet to the execution log."],["For production environments, further exploration of authentication, authorization, and credential management is recommended."]]],["This document outlines setting up and running a Google Apps Script that interacts with the Google Sheets API. Key actions include: configuring the environment, creating a script, enabling the Sheets API service, and running the script. The script accesses a sample spreadsheet, retrieves student names and majors, and logs them. Authentication authorization is required initially. Client libraries for API are recommended. It also provides links for advanced learning, troubleshooting and bug reporting.\n"]]