الوصول إلى خصائص هوية المستخدم
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
سيستخدم المستخدمون "موصِّل المنتدى" لإنشاء مصادر البيانات الخاصة بهم. بالنسبة لمصادر البيانات هذه، يمكن للموصل الوصول إلى هوية المستخدم الفعالة.
استنادًا إلى بيانات اعتماد مصدر البيانات، قد يكون المستخدم الفعال هو منشئ
مصدر البيانات (بيانات اعتماد المالك) أو مُشاهد التقارير (بيانات اعتماد المُشاهد).
المزايا
- يمكنك الوصول إلى خدمات Google وواجهات برمجة التطبيقات بالنيابة عن المستخدم.
- يمكنك تنفيذ تحكم مخصص في الوصول لضمان عرض البيانات ذات الصلة فقط.
- ويمكنك تخصيص تجربة المستخدم للمستخدم الفعال.
خطوات التنفيذ
الوصول إلى رمز OAuth المميز للمستخدم
يمكن للموصّل الوصول إلى خدمات Google وواجهات برمجة التطبيقات نيابةً عن المستخدم من خلال تمرير رمز OAuth المميز للمستخدم. للوصول إلى رمز OAuth المميز للمستخدم الفعال في
الموصِّل، استخدِم ScriptApp.getOAuthToken()
. راجِع مرجع getOAuthToken.
سيتضمن هذا الرمز المميز نطاقات التفويض المضمنة أثناء تفويض الموصِّل.
بالنسبة إلى معظم الموصِّلات، ترصد لغة "برمجة تطبيقات Google" تلقائيًا النطاقات المطلوبة من خلال تحليل النص البرمجي ومعالجته. يمكنك عرض النطاقات التي يستخدمها الموصِّل في أي وقت. يمكنك أيضًا ضبط النطاقات بوضوح في البيان باستخدام سلاسل عناوين URL. إذا كنت تريد الوصول إلى إحدى خدمات Google أو واجهة برمجة التطبيقات نيابةً عن المستخدم،
عليك تضمين هذا النطاق ذي الصلة في البيان.
الوصول إلى عنوان البريد الإلكتروني للمستخدم
في الرمز الخاص بك، يمكنك تحديد المستخدم الفعّال الحالي من خلال
Session.getEffectiveUser().getEmail()
. اطّلِع على مرجع geteffectiveUser.
ستؤدي إضافة هذا الرمز تلقائيًا إلى إضافة نطاق تفويض https://www.googleapis.com/auth/userinfo.email
إلى الموصل
مثال: استدعاء واجهات Google APIs باستخدام رمز OAuth المميّز للمستخدم
- يجلب موصِّل Google Fit البيانات من Google Fit API للمستخدم الفعّال. وأثناء استدعاء واجهة برمجة التطبيقات، تمرر رمز OAuth المميز للمستخدم الفعال. راجِع رمز المصدر للتعرّف على تفاصيل التنفيذ.
- يستخدم موصِّل Firestore تطبيق Cloud Resource Manager للحصول على قائمة بالمشاريع للمستخدم الفعّال. ويمرر هذا الموصل أيضًا رمز OAuth المميز
الفعال للمستخدم. راجِع رمز المصدر للحصول على
تفاصيل التنفيذ.
مثال: isAdminUser()
استنادًا إلى عنوان البريد الإلكتروني
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-07-25 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-07-25 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\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)."]]