Embed SDK 試用版

Looker Embed SDK 存放區包含範例程式碼和 Embed SDK 的示範。由於 Looker 的安全性規定,因此示範需要進行一些設定。這個示範也需要您的 Looker 嵌入密碼。嵌入密碼會授予存取所有資料的權限,因此請注意下列事項:

  • 請勿將機密金鑰提供給不應完全存取執行個體的使用者。
  • 如果您已在其他情境中使用機密金鑰,請勿重設。
  • 請勿設定程式碼,以便在網頁瀏覽器中儲存密鑰。

步驟 1:在 Looker 執行個體中啟用嵌入功能

詳情請參閱「已簽署的嵌入」說明文件頁面。

  1. 在 Looker 執行個體中,依序前往「管理」>「平台嵌入」,這項操作需要管理員權限。
  2. 根據預設,示範伺服器會在 http://localhost:8080 上執行。將該地址加入內嵌網域許可清單,即可讓示範專案接收 Looker 傳送的訊息。
  3. 開啟「嵌入驗證」
  4. 如要查看嵌入密鑰,您必須重設密鑰。將機密金鑰複製到安全的位置。

步驟 2:自訂 Looker 執行個體的示範設定

將嵌入密鑰提供給伺服器。您可以選擇下列其中一種操作方式:

  • 在 Shell 環境中將其設為 LOOKER_EMBED_SECRET
  • 在 sdk 目錄的根目錄中建立名為 .env 的檔案。在該檔案中新增一行:LOOKER_EMBED_SECRET="YourLookerSecret"

請使用下列任一方法,將 Looker 執行個體主機位址提供給伺服器:

  • 在 Shell 環境中將其設為 LOOKER_WEB_URL
  • LOOKER_WEB_URL="yourinstance.looker.com:yourport" 新增至 .env 檔案。

編輯 ENV 檔案,指定要嵌入的內容 ID。

# Looker Embed Data Configuration
# Set to - if demo needs to ignore it

# Dashboard IDs
LOOKER_DASHBOARD_ID=1
LOOKER_DASHBOARD_ID_2=2
# Look ID
LOOKER_LOOK_ID=1
# Explore ID
LOOKER_EXPLORE_ID=model::explore
# Extension ID
LOOKER_EXTENSION_ID=extension::my-great-extension
# Report ID
LOOKER_REPORT_ID=aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
# Query Visualization ID
LOOKER_QUERY_VISUALIZATION_ID=1234567890ABCDEF123456

編輯 demo/demo_user.json 檔案,以便根據您要嵌入的使用者類型進行調整。

{
  // External embed user ID. IDs are not shared with regular users. Required
  "external_user_id": "user1",
  // First and last name. Optional
  "first_name": "Pat",
  "last_name": "Embed",
  // Duration before session expires, in seconds. Required.
  "session_length": 3600,
  // Enforce logging in with these permissions. Recommended.
  "force_logout_login": true,
  // External embed group ID. Optional.
  "external_group_id": "group1",
  // Looker Group IDs. Optional
  "group_ids": [],
  // Permissions. See documentation for details. Required.
  // Can any combination of:
  //   access_data
  //   see_looks
  //   see_user_dashboards
  //   see_lookml_dashboards
  //   explore
  //   create_table_calculations
  //   download_with_limit
  //   download_without_limit
  //   see_drill_overlay
  //   see_sql
  //   save_content
  //   embed_browse_spaces
  //   schedule_look_emails
  //   send_to_sftp
  //   send_to_s3
  //   send_outgoing_webhook
  //   schedule_external_look_emails
  "permissions": [
    "access_data",
    "see_looks",
    "see_user_dashboards",
    "explore",
    "save_content",
    "embed_browse_spaces"
  ],
  // Model access permissions. Required.
  "models": ["powered_by", "thelook"],
  // User attributes. Optional.
  "user_attributes": { "locale": "en_US" },
}

步驟 3:建構並執行示範

如要建構及執行示範,請按照適當伺服器的步驟操作。

節點伺服器

  1. 執行 npm install
  2. 執行 npm start

伺服器會列印出正在執行的主機和通訊埠。如果與 http://localhost:8080 不同,您必須將其加入嵌入式網域許可清單

Python 伺服器

  1. 執行 npm install
  2. 執行 npm run python

伺服器會列印出正在執行的主機和通訊埠。

您可能需要pip install six來安裝 Python 2/3 相容性層。