En las guías de inicio rápido, se explica cómo configurar y ejecutar una app que llama a una API de Google Workspace. En esta guía de inicio rápido, se usa un enfoque de autenticación simplificado que es adecuado para un entorno de pruebas. Para un entorno de producción, te recomendamos que obtengas información sobre la autenticación y la autorización antes de elegir las credenciales de acceso adecuadas para tu app.
En Apps Script, los inicios rápidos de Google Workspace usan los servicios avanzados de Google para llamar a las APIs de Google Workspace y controlar algunos detalles del flujo de autenticación y autorización.
/** * Print the display name if available for 10 connections. */functionlistConnectionNames(){try{/** * List the 10 connections/contacts of user * @see https://developers.google.com/people/api/rest/v1/people.connections/list */constconnections=People.People.Connections.list('people/me',{pageSize:10,personFields:'names,emailAddresses'// use other query parameter here if needed.});connections.connections.forEach((person)=>{// if contacts/connections is available, print the name of person.if(person.names && person.names.length===0){console.log('No display name found for connection.');return;}console.log(person.names[0].displayName);});}catch(err){// TODO (developer) - Handle exception from People APIconsole.log('Failed with error %s',err.message);}}
Haz clic en Guardar .
Haz clic en Proyecto sin título, escribe Quickstart y haz clic en Cambiar nombre.
Configura la secuencia de comandos
Habilita la API de People
Abre el proyecto de Apps Script.
Haz clic en Editorcode.
Junto a Servicios, haz clic en Agregar un servicio
add .
Selecciona la API de People y haz clic en Agregar.
Ejecuta la muestra
En el editor de Apps Script, haz clic en Ejecutar.
La primera vez que ejecutes la muestra, se te solicitará que autorices el acceso:
Haz clic en Revisar permisos.
Elige una cuenta.
Haz clic en Permitir.
El registro de ejecución de la secuencia de comandos aparece en la parte inferior de la ventana.
[null,null,["Última actualización: 2025-09-04 (UTC)"],[[["\u003cp\u003eThis quickstart demonstrates how to use Google Apps Script to access the People API and retrieve a list of connections.\u003c/p\u003e\n"],["\u003cp\u003eBefore starting, ensure you have a Google Workspace domain with API access enabled and a Google Account with administrator privileges.\u003c/p\u003e\n"],["\u003cp\u003eThe guide walks you through creating, configuring, and running a script that prints the display names of your connections.\u003c/p\u003e\n"],["\u003cp\u003eYou'll need to enable the People API in your Apps Script project and authorize the script to access your Google account.\u003c/p\u003e\n"],["\u003cp\u003eFor production environments, Google recommends reviewing authentication and authorization best practices.\u003c/p\u003e\n"]]],["This document guides users to create and run a Google Apps Script that interacts with the People API. It involves configuring a new script on `script.google.com`, replacing the script editor's content with provided code, saving, and renaming the project. Users must enable the People API as a service within the script and authorize access during the initial run. The script then lists the display names of 10 connections. Production environments need appropriate authentication credentials.\n"],null,["Create a\n[Google Apps Script](/apps-script/overview)\nthat makes requests to the People API.\n\nQuickstarts explain how to set up and run an app that calls a\nGoogle Workspace API. This quickstart uses a\nsimplified authentication approach that is appropriate for a testing\nenvironment. For a production environment, we recommend learning about\n[authentication and authorization](/workspace/guides/auth-overview)\nbefore\n[choosing the access credentials](/workspace/guides/create-credentials#choose_the_access_credential_that_is_right_for_you)\nthat are appropriate for your app.\n\nIn Apps Script, Google Workspace\nquickstarts use\n[Advanced Google services](/apps-script/guides/services/advanced) to call\nGoogle Workspace APIs and handle some details of the authentication\nand authorization flow.\n\nObjectives\n\n- Configure the environment.\n- Create and configure the script.\n- Run the script.\n\nPrerequisites\n\n\n- A Google Workspace domain with [API access enabled](https://support.google.com/a/answer/60757).\n- A Google Account in that domain with administrator privileges.\n\n\u003cbr /\u003e\n\n- Access to Google Drive\n\nCreate the script\n\n1. Create a new script in the Apps Script editor by going to [script.google.com/create](https://script.google.com/create).\n2. Replace the contents of the script editor with the following code:\n\n\npeople/quickstart/quickstart.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/people/quickstart/quickstart.gs) \n\n```javascript\n/**\n * Print the display name if available for 10 connections.\n */\nfunction listConnectionNames() {\n try {\n /**\n * List the 10 connections/contacts of user\n * @see https://developers.google.com/people/api/rest/v1/people.connections/list\n */\n const connections = People.People.Connections.list('people/me', {\n pageSize: 10,\n personFields: 'names,emailAddresses'\n // use other query parameter here if needed.\n });\n connections.connections.forEach((person) =\u003e {\n // if contacts/connections is available, print the name of person.\n if (person.names && person.names.length === 0) {\n console.log('No display name found for connection.');\n return;\n }\n console.log(person.names[0].displayName);\n });\n } catch (err) {\n // TODO (developer) - Handle exception from People API\n console.log('Failed with error %s', err.message);\n }\n}\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n3. Click Save .\n4. Click **Untitled project** , type **Quickstart** , and click **Rename**.\n\n\u003cbr /\u003e\n\nConfigure the script\n\nEnable the People API\n\nOpen the Apps Script project.\n\n1. Click **Editor** code.\n2. Next to **Services** , click Add a service add .\n3. Select People API and click **Add**.\n\nRun the sample\n\nIn the Apps Script editor, click **Run**.\n\nThe first time you run the sample, it prompts you to authorize access:\n\n1. Click **Review permissions**.\n2. Choose an account.\n3. Click **Allow**.\n\nThe script's execution log appears at the bottom of the window. \ndone It worked! **Great!** Check out the further reading section below to learn more.\nwarning There was a problem **Bummer** , thanks for letting us know. Check out our [troubleshooting](#troubleshooting) section below for some common errors and solutions. If you have found a bug in the code, [report the issue on GitHub](https://github.com/googleworkspace/apps-script-samples/issues) or submit a pull request.\n\nNext steps\n\n- [Google Apps Script Advanced Services documentation](/apps-script/guides/services/advanced)\n- [Try the Google Workspace APIs in the APIs explorer](/workspace/explore)\n- [Troubleshoot authentication and authorization issues](/people/v1/troubleshoot-authentication-authorization)\n- [People API reference documentation](/people/api)"]]