启用缩略图

缩略图有助于用户识别相关的搜索结果。它们具有以下特征:

  • 宽度为 1024 像素。
  • Google Workspace 文件缩略图的网址受 ACL 保护。其他文件类型则不支持。
  • 网址会在 5 分钟后失效。
  • 生成内容所用文件的最大大小为 50 MB。
  • 如果生成失败,Cloud Search 会返回占位图标。对于 Google Workspace 项目,该网址会返回“404 Not Found”。您的应用必须处理此情况。

Google 云端硬盘会自动为受支持的类型(例如 Google 文档、表格和幻灯片)创建缩略图。 Cloud Search 还会为以下内容生成缩略图:

  • Microsoft Word (DOC、DOCX)
  • Microsoft Excel (XLS、XLSX)
  • Microsoft PowerPoint(PPT、PPTX)
  • Adobe PDF
  • RTF、TXT、HTML 和 XML

仅当您为数据源和搜索应用启用缩略图时,Cloud Search 才会返回项的缩略图。

为数据源启用缩略图网址

如需启用缩略图网址,请创建 API 密钥和 Web 应用凭据。使用这些信息获取访问令牌,以更新数据源。

  1. 创建或选择一个项目并启用相应 API。请参阅配置对 Cloud Search API 的访问权限
  2. 在 Google Cloud 控制台中创建 API 密钥,并记下该值。
  3. 创建 Web 应用凭据。使用 https://developers.google.com/oauthplayground 作为重定向 URI。请参阅创建凭据
  4. OAuth 2.0 Playground 中,打开 OAuth 2.0 配置
  5. 选择使用您自己的凭据,然后输入您的客户端 ID 和密钥。
  6. 在范围字段中输入 https://www.googleapis.com/auth/cloud_search.settings,然后点击 Authorize APIs
  7. 将授权代码兑换为令牌。
  8. 调用 settings.datasources.get 以获取数据源 ID:

    curl 'https://cloudsearch.googleapis.com/v1/settings/DATASOURCE_ID?key=YOUR_API_KEY' \
    --header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
    --header 'Accept: application/json' \
    --compressed
    
  9. 调用 settings.datasources.update,并将 returnThumbnailUrls 设置为 true

    curl --request PUT \
    'https://cloudsearch.googleapis.com/v1/settings/datasources/DATASOURCE_ID?key=YOUR_API_KEY' \
    --header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
    --header 'Accept: application/json' \
    --header 'Content-Type: application/json' \
    --data '{"source":{"name":"datasources/DATASOURCE_ID","displayName":"DISPLAY_NAME","itemsVisibility":[{"gsuiteDomain":true}],"returnThumbnailUrls":true}}' \
    --compressed
    

为搜索应用启用缩略图网址

您还必须在搜索应用中启用缩略图。

  1. 使用上一部分中描述的相同方法获取 API 密钥和访问令牌。
  2. 调用 settings.searchapplications.get 以获取应用 ID:

    curl 'https://cloudsearch.googleapis.com/v1/settings/searchapplications/APP_ID?key=YOUR_API_KEY' \
    --header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
    --header 'Accept: application/json' \
    --compressed
    
  3. 调用 settings.searchapplications.update,并将 returnResultThumbnailUrls 设置为 true

    curl --request PUT \
    'https://cloudsearch.googleapis.com/v1/settings/searchapplications/APP_ID?key=YOUR_API_KEY' \
    --header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
    --header 'Accept: application/json' \
    --header 'Content-Type: application/json' \
    --data '{"name":"searchapplications/APP_ID","displayName":"DISPLAY_NAME","dataSourceRestrictions":[{"source":{"name":"datasources/DATASOURCE_ID"}}],"returnResultThumbnailUrls":true}' \
    --compressed
    

访问缩略图

如需访问云端硬盘文件的缩略图,用户或应用必须使用与访问原始文件时相同的账号凭据。