Zaawansowana usługa osób
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Zaawansowana usługa People umożliwia korzystanie z People API w Apps Script. Ten interfejs API umożliwia skryptom tworzenie, odczytywanie i aktualizowanie danych kontaktowych zalogowanego użytkownika oraz odczytywanie danych profilu użytkowników Google.
Dokumentacja
Szczegółowe informacje o tej usłudze znajdziesz w dokumentacji referencyjnej interfejsu People API.
Podobnie jak wszystkie usługi zaawansowane w Apps Script, zaawansowana usługa People korzysta z tych samych obiektów, metod i parametrów co publiczny interfejs API. Więcej informacji znajdziesz w artykule Jak określane są sygnatury metod.
Aby zgłosić problemy i uzyskać inną pomoc, zapoznaj się z przewodnikiem pomocy dotyczącym interfejsu People API w wersji 1.
Przykładowy kod
Poniższy przykładowy kod korzysta z wersji 1 interfejsu API.
Pobieranie połączeń użytkownika
Aby pobrać listę osób z kontaktów użytkownika, użyj tego kodu:
Pobieranie osoby dla użytkownika
Aby uzyskać profil użytkownika, musisz poprosić o zakres https://www.googleapis.com/auth/userinfo.profile
, postępując zgodnie z instrukcjami dodawania jawnych zakresów do pliku manifestu appsscript.json
. Po dodaniu zakresu możesz użyć tego kodu:
Pobieranie informacji o osobie z konta Google
Aby uzyskać informacje o osobie powiązanej z dowolnym kontem Google, użyj tego kodu:
O ile nie stwierdzono inaczej, treść tej strony jest objęta licencją Creative Commons – uznanie autorstwa 4.0, a fragmenty kodu są dostępne na licencji Apache 2.0. Szczegółowe informacje na ten temat zawierają zasady dotyczące witryny Google Developers. Java jest zastrzeżonym znakiem towarowym firmy Oracle i jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-08-31 UTC.
[null,null,["Ostatnia aktualizacja: 2025-08-31 UTC."],[[["\u003cp\u003eThe advanced People service in Apps Script utilizes the People API to manage contact data for the logged-in user and access Google user profiles.\u003c/p\u003e\n"],["\u003cp\u003eThis advanced service needs to be enabled before use and mirrors the functionality of the public People API.\u003c/p\u003e\n"],["\u003cp\u003eScripts can create, read, and update contact details for the current user, as well as retrieve profile information for other Google users.\u003c/p\u003e\n"],["\u003cp\u003eSample code snippets are provided to demonstrate functionalities like fetching user connections, retrieving the user's own profile, and getting information for any Google Account by ID.\u003c/p\u003e\n"]]],[],null,["# Advanced People Service\n\nThe advanced People service allows you to use the\n[People API](/people) in Apps Script. This API allows scripts\nto create, read, and update contact data for the logged in user and read profile\ndata for google users.\n| **Note:** This is an advanced service that must be [enabled before use](/apps-script/guides/services/advanced).\n\nReference\n---------\n\nFor detailed information on this service, see the\n[reference documentation](/people/api/rest) for the People API.\nLike all advanced services in Apps Script, the advanced People service uses the\nsame objects, methods, and parameters as the public API. For more information, see [How method signatures are determined](/apps-script/guides/services/advanced#how_method_signatures_are_determined).\n\nTo report issues and find other support, see the\n[People v1 support guide](/people/support).\n\nSample code\n-----------\n\nThe sample code below uses [version 1](/people/api/rest) of the API.\n\n### Get the user's connections\n\nTo [get a list of people in the user's contacts](/people/api/rest/v1/people.connections/list),\nuse the following code: \nadvanced/people.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/people.gs) \n\n```javascript\n/**\n * Gets a list of people in the user's contacts.\n * @see https://developers.google.com/people/api/rest/v1/people.connections/list\n */\nfunction getConnections() {\n try {\n // Get the list of connections/contacts of user's profile\n const people = People.People.Connections.list('people/me', {\n personFields: 'names,emailAddresses'\n });\n // Print the connections/contacts\n console.log('Connections: %s', JSON.stringify(people, null, 2));\n } catch (err) {\n // TODO (developers) - Handle exception here\n console.log('Failed to get the connection with an error %s', err.message);\n }\n}\n```\n\n### Get the person for the user\n\nTo [get the user's profile](/people/api/rest/v1/people/get), you need to request\nthe `https://www.googleapis.com/auth/userinfo.profile` scope by following the\n[instructions to add explicit scopes](/apps-script/concepts/scopes#setting_explicit_scopes)\nto your `appsscript.json` manifest file. Once the scope is added, you can use\nthe following code: \nadvanced/people.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/people.gs) \n\n```javascript\n/**\n * Gets the own user's profile.\n * @see https://developers.google.com/people/api/rest/v1/people/getBatchGet\n */\nfunction getSelf() {\n try {\n // Get own user's profile using People.getBatchGet() method\n const people = People.People.getBatchGet({\n resourceNames: ['people/me'],\n personFields: 'names,emailAddresses'\n // Use other query parameter here if needed\n });\n console.log('Myself: %s', JSON.stringify(people, null, 2));\n } catch (err) {\n // TODO (developer) -Handle exception\n console.log('Failed to get own profile with an error %s', err.message);\n }\n}\n```\n\n### Get the person for a Google Account\n\nTo [get the person information for any Google Account](/people/api/rest/v1/people/get),\nuse the following code: \nadvanced/people.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/people.gs) \n\n```javascript\n/**\n * Gets the person information for any Google Account.\n * @param {string} accountId The account ID.\n * @see https://developers.google.com/people/api/rest/v1/people/get\n */\nfunction getAccount(accountId) {\n try {\n // Get the Account details using account ID.\n const people = People.People.get('people/' + accountId, {\n personFields: 'names,emailAddresses'\n });\n // Print the profile details of Account.\n console.log('Public Profile: %s', JSON.stringify(people, null, 2));\n } catch (err) {\n // TODO (developer) - Handle exception\n console.log('Failed to get account with an error %s', err.message);\n }\n}\n```"]]