Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Utwórz Google Apps Script, który wysyła żądania do interfejsu People API.
Przewodniki szybkiego startu wyjaśniają, jak skonfigurować i uruchamiać aplikację, która wywołuje interfejs Google Workspace API. W tym krótkim wprowadzeniu użyjemy uproszczonego podejścia do uwierzytelniania, które jest odpowiednie dla środowiska testowego. W przypadku środowiska produkcyjnego zalecamy zapoznanie się z informacjami na temat uwierzytelniania i autoryzacji, zanim wybierzesz odpowiednie dla swojej aplikacji poświadczenia dostępu.
W Apps Script quickstarty Google Workspace korzystają z zaawansowanych usług Google, aby wywoływać interfejsy API Google Workspace i obsługiwać niektóre szczegóły procesu uwierzytelniania oraz autoryzacji.
/** * 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('Nodisplaynamefoundforconnection.');return;}console.log(person.names[0].displayName);});}catch(err){// TODO (developer) - Handle exception from People APIconsole.log('Failedwitherror%s',err.message);}}
Kliknij Zapisz .
Kliknij Projekt bez tytułu, wpisz Szybki start i kliknij Zmień nazwę.
Konfigurowanie skryptu
Włączanie People API
Otwórz projekt Apps Script.
Kliknij Edytorcode.
Obok opcji Usługi kliknij Dodaj usługęadd .
Kliknij People API i Dodaj.
Uruchamianie przykładu
W edytorze Apps Script kliknij Uruchom.
Gdy uruchomisz próbkę po raz pierwszy, pojawi się prośba o autoryzację dostępu:
Kliknij Przejrzyj uprawnienia.
Wybierz konto.
Kliknij Zezwól.
U dołu okna pojawi się dziennik wykonania skryptu.
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 2025-07-03 UTC."],[[["This quickstart demonstrates how to use Google Apps Script to access the People API and retrieve a list of connections."],["Before starting, ensure you have a Google Workspace domain with API access enabled and a Google Account with administrator privileges."],["The guide walks you through creating, configuring, and running a script that prints the display names of your connections."],["You'll need to enable the People API in your Apps Script project and authorize the script to access your Google account."],["For production environments, Google recommends reviewing authentication and authorization best practices."]]],["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"]]