เข้าถึงพร็อพเพอร์ตี้การระบุตัวตนของผู้ใช้
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ผู้ใช้จะใช้เครื่องมือเชื่อมต่อชุมชนเพื่อสร้างแหล่งข้อมูลของตนเอง สำหรับแหล่งข้อมูลเหล่านี้ เครื่องมือเชื่อมต่อของคุณจะเข้าถึงข้อมูลประจำตัวของผู้ใช้ที่มีประสิทธิภาพได้
ผู้ใช้ที่มีประสิทธิภาพอาจเป็นผู้สร้างแหล่งข้อมูล (ข้อมูลเข้าสู่ระบบของเจ้าของ) หรือผู้ดูรายงาน (ข้อมูลเข้าสู่ระบบของผู้ดู) ก็ได้ ทั้งนี้ขึ้นอยู่กับข้อมูลเข้าสู่ระบบของแหล่งข้อมูล
ข้อดี
- คุณสามารถเข้าถึงบริการและ API ของ Google ในนามของผู้ใช้ได้
- คุณสามารถใช้การควบคุมการเข้าถึงที่กำหนดเองเพื่อให้มั่นใจว่าระบบจะแสดงเฉพาะข้อมูลที่เกี่ยวข้องเท่านั้น
- คุณปรับแต่งประสบการณ์ของผู้ใช้ให้เหมาะกับผู้ใช้ได้
ขั้นตอนการใช้งาน
การเข้าถึงโทเค็น OAuth ของผู้ใช้
เครื่องมือเชื่อมต่อของคุณสามารถเข้าถึงบริการและ API ของ Google ในนามของผู้ใช้โดยการส่งโทเค็น OAuth ของผู้ใช้ หากต้องการเข้าถึงโทเค็น OAuth ของผู้ใช้ที่มีประสิทธิภาพใน
เครื่องมือเชื่อมต่อของคุณ ให้ใช้ ScriptApp.getOAuthToken()
โปรดดูที่ข้อมูลอ้างอิง getOAuthToken
โทเค็นนี้จะรวมขอบเขตการให้สิทธิ์ที่อยู่ในระหว่างการให้สิทธิ์เครื่องมือเชื่อมต่อ
สำหรับเครื่องมือเชื่อมต่อส่วนใหญ่ Apps Script จะตรวจหาขอบเขตที่จำเป็นโดยอัตโนมัติด้วยการแยกวิเคราะห์และประมวลผลสคริปต์ คุณจะดูขอบเขตที่เครื่องมือเชื่อมต่อใช้ได้ทุกเมื่อ นอกจากนี้คุณยังตั้งขอบเขตอย่างชัดแจ้งในไฟล์ Manifest ได้โดยใช้สตริง URL หากต้องการเข้าถึงบริการหรือ API ของ Google ในนามของผู้ใช้ ให้ใส่ขอบเขตที่เกี่ยวข้องในไฟล์ Manifest
การเข้าถึงที่อยู่อีเมลของผู้ใช้
คุณสามารถระบุผู้ใช้ที่มีประสิทธิภาพในปัจจุบันได้ด้วย Session.getEffectiveUser().getEmail()
ในโค้ด โปรดดูข้อมูลอ้างอิง getEffectiveUser
การเพิ่มโค้ดนี้จะเพิ่มขอบเขตการให้สิทธิ์ https://www.googleapis.com/auth/userinfo.email
ลงในเครื่องมือเชื่อมต่อของคุณโดยอัตโนมัติ
ตัวอย่าง: การเรียกใช้ Google API ด้วยโทเค็น OAuth ของผู้ใช้
- เครื่องมือเชื่อมต่อ Google Fit จะดึงข้อมูลจาก Google Fit API สำหรับผู้ใช้ที่มีประสิทธิภาพ ขณะเรียกใช้ API รหัสจะส่งผ่านโทเค็น OAuth ของผู้ใช้ที่มีประสิทธิภาพ ดูรายละเอียดการใช้งานได้ที่ซอร์สโค้ด
- เครื่องมือเชื่อมต่อ Firestore ใช้ Cloud Resource Manager เพื่อรับรายการโปรเจ็กต์สำหรับผู้ใช้ที่มีประสิทธิภาพ เครื่องมือเชื่อมต่อนี้จะส่งโทเค็น OAuth
ของผู้ใช้ที่มีประสิทธิภาพด้วย ดูซอร์สโค้ดสำหรับรายละเอียดการใช้งาน
ตัวอย่าง: isAdminUser()
ตามอีเมล
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-25 UTC
[null,null,["อัปเดตล่าสุด 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)."]]