嵌入 SDK 演示

Looker Embed SDK 代码库包含示例代码和 Embed SDK 的简单演示。由于 Looker 注重安全性,因此该演示需要一些设置。此演示还需要您的 Looker 嵌入密钥。嵌入密钥会授予对您所有数据的访问权限,因此请注意以下事项:

  • 请勿与您不希望获得实例完整访问权限的任何人共享您的密钥。
  • 如果您已在其他上下文中使用密钥,请勿重置密钥。
  • 请勿将代码设置为在网络浏览器中存储 Secret。

第 1 步:在 Looker 实例中启用嵌入

签名嵌入文档页面对此进行了更详细的说明。

  1. 转到管理 >平台嵌入。这需要管理员权限。
  2. 默认情况下,演示服务器在 http://localhost:8080 运行。将该地址添加到嵌入式网域许可名单后,演示版本即可接收来自 Looker 的消息。
  3. 开启嵌入身份验证
  4. 若要查看您的嵌入密钥,您必须重置它。将密钥复制到安全的位置。

第 2 步:自定义 Looker 实例的演示设置

向服务器提供您的嵌入密钥。为此,您可以采用以下几种方法:

  • 在 shell 环境中将其设置为 LOOKER_EMBED_SECRET
  • 在 SDK 目录的根目录下创建一个名为 .env 的文件。向该文件添加一行代码:LOOKER_EMBED_SECRET="YourLookerSecret"

通过以下任一方式向服务器提供 Looker 实例主机地址:

  • 在 shell 环境中将其设置为 LOOKER_EMBED_HOST
  • LOOKER_EMBED_HOST="yourinstance.looker.com:yourport" 添加到 .env 文件中。

修改 demo/demo_config.ts 文件,使其适合要嵌入的页面。

// The address of your Looker instance. Required.
export const lookerHost = 'self-signed.looker.com:9999'

// A dashboard that the user can see. Set to 0 to disable dashboard.
export const dashboardId = 1
// A Look that the user can see. Set to 0 to disable look.
export const lookId = 1

修改 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 兼容层。