Dostęp do właściwości tożsamości użytkownika
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Użytkownicy będą używać Twojego społecznościowego oprogramowania sprzęgającego do tworzenia własnych źródeł danych. W przypadku tych źródeł danych oprogramowanie sprzęgające ma dostęp do tożsamości użytkownika.
W zależności od danych logowania do źródła danych rzeczywistym użytkownikiem może być twórca źródła danych (dane logowania właściciela) lub wyświetlający raport (dane logowania osoby przeglądającej).
Zalety
- Możesz uzyskiwać dostęp do usług i interfejsów API Google w imieniu użytkownika.
- Możesz wdrożyć niestandardową kontrolę dostępu, aby mieć pewność, że wyświetlane są tylko istotne dane.
- Możesz dostosować wrażenia użytkownika do ich potrzeb.
Etapy wdrażania
Dostęp do tokena OAuth użytkownika
Oprogramowanie sprzęgające może uzyskiwać dostęp do usług i interfejsów API Google w imieniu użytkownika, przekazując jego token OAuth. Aby uzyskać dostęp do tokena OAuth odpowiedniego użytkownika w oprogramowaniu sprzęgającym, użyj ScriptApp.getOAuthToken()
. Zobacz dokumentację getOAuthToken.
Ten token będzie zawierał zakresy autoryzacji uwzględnione podczas autoryzacji oprogramowania sprzęgającego.
W przypadku większości programów sprzęgających Apps Script przez analizowanie i przetwarzanie skryptu automatycznie wykrywa, które zakresy są potrzebne. W każdej chwili możesz wyświetlić zakresy używane przez oprogramowanie sprzęgające. Możesz też ustawić zakresy wyraźnie w pliku manifestu za pomocą ciągów adresów URL. Jeśli chcesz uzyskać dostęp do usługi Google lub interfejsu API w imieniu użytkownika, umieść odpowiedni zakres w pliku manifestu.
Dostęp do adresu e-mail użytkownika
W kodzie możesz zidentyfikować obecnego efektywnego użytkownika za pomocą Session.getEffectiveUser().getEmail()
. Zobacz dokumentację getEffectiveUser.
Dodanie tego kodu spowoduje automatyczne dodanie zakresu autoryzacji https://www.googleapis.com/auth/userinfo.email
do oprogramowania sprzęgającego.
Przykład: wywoływanie interfejsów API Google za pomocą tokena protokołu OAuth użytkownika
Przykład: isAdminUser()
na podstawie adresu e-mail
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-07-25 UTC.
[null,null,["Ostatnia aktualizacja: 2025-07-25 UTC."],[[["\u003cp\u003eCommunity Connectors allow you to build data sources that can access the effective user's identity, enabling personalized data retrieval.\u003c/p\u003e\n"],["\u003cp\u003eDepending on the data source credentials, the effective user can be either the data source creator or the report viewer.\u003c/p\u003e\n"],["\u003cp\u003eYour connector can leverage the user's OAuth token to access Google services and APIs on their behalf for custom data integrations.\u003c/p\u003e\n"],["\u003cp\u003eYou can tailor the user experience by implementing custom access control and using the user's email address for identification.\u003c/p\u003e\n"]]],[],null,["# Access user identity properties\n\nUsers will use your Community Connector to create their own data sources. For\nthese data sources, your connector can access the effective user's identity.\nDepending on the [Data source credentials](https://support.google.com/looker-studio/answer/6371135), the effective user can be the data\nsource creator (Owner's credentials) or the report viewer (Viewer's\ncredentials).\n\nBenefits\n--------\n\n- You can access Google services and APIs on behalf of the user.\n- You can implement custom access control to ensure only relevant data is being displayed.\n- You can customize the user experience for the effective user.\n\nImplementation steps\n--------------------\n\n### Accessing the user OAuth token\n\nYour connector can access Google services and APIs on behalf of the user by\npassing the user's OAuth token. To access the effective user's OAuth token in\nyour connector, use `ScriptApp.getOAuthToken()`. See [getOAuthToken reference](/apps-script/reference/script/script-app#getoauthtoken).\nThis token will include the [Authorization scopes](/apps-script/concepts/scopes) included during the connector\nauthorization.\n\nFor most connectors, Apps Script automatically detects what scopes are needed by\nparsing and processing the script. You can [view the scopes](/apps-script/concepts/scopes#viewing_scopes) a connector uses at\nany time. You can also [set scopes explicitly](/apps-script/concepts/scopes#setting_explicit_scopes) in your [manifest](/apps-script/concepts/manifests) using URL\nstrings. If you want to access a Google service or API on behalf of the user,\ninclude that relevant scope in the manifest.\n\n### Accessing the user email address\n\nIn your code, you can identify the current effective user with\n`Session.getEffectiveUser().getEmail()`. See [getEffectiveUser reference](/apps-script/reference/base/session#getEffectiveUser).\nAdding this code will automatically add the\n`https://www.googleapis.com/auth/userinfo.email` authorization scope to your\nconnector.\n\nExample: Calling Google APIs with user OAuth token\n--------------------------------------------------\n\n- The [Google Fit connector](https://lookerstudio.google.com/datasources/create?connectorId=AKfycbwFrL1OLXR3wqfnxowGFF3w3D4eq-54vAwjxDWcWRjiZMxX7jhII_1Ddx6y76GDHrxIew) fetches data from the Google Fit API for the effective user. While calling the API, it passes the effective user's OAuth token. See [the source code](https://github.com/googledatastudio/community-connectors/blob/master/google-fit/src/GoogleFit.js#L245) for implementation details.\n- The [Firestore connector](https://github.com/googledatastudio/community-connectors/tree/master/firestore) uses the Cloud Resource Manager to get a list of projects for the effective user. This connector also passes the effective user's OAuth token. See [the source code](https://github.com/googledatastudio/community-connectors/blob/master/firestore/src/GoogleCloud.gs#L30) for implementation details.\n\nExample: `isAdminUser()` based on email address\n-----------------------------------------------\n\n- The [Chrome UX Connector](http://g.co/chromeuxdash) maintains a list of admin users. It uses `getEffectiveUser()` and compares the effective user against the list to determine whether the effective user is an admin or not. See [implementation of `getEffectiveUser`](https://github.com/googledatastudio/community-connectors/blob/master/chrome-ux-report/src/Code.js#L581)."]]