[TITLE]
在 Odoo 中使用 Google 自定义搜索 API 批量获取产品图片

[DESCRIPTION]
本文介绍如何在 Odoo 中配置 Google Custom Search API,实现基于条形码的产品图片自动获取。涵盖 Google Cloud API、Programmable Search Engine 设置以及 Odoo 集成步骤,帮助用户快速批量为产品添加图片。

[KEYWORDS]
Odoo,Google 图片,自定义搜索 API,产品图片,自动化,条形码,Google 云平台,Programmable Search Engine,集成,图像检索

[TRANSLATED_CONTENT]

# 使用 Google 图片的产品图像

拥有合适的产品图片在 Odoo 中有诸多用途。然而,当需要为大量产品分配图片时,手动操作会非常耗时。

幸运的是,通过在 Odoo 数据库中配置 *Google Custom Search* API,基于条形码为产品寻找图片的效率极高。

## 配置 {#product_images/configuration}

要在 Odoo 数据库中使用 *Google Custom Search*,必须正确配置数据库和 Google API。

:::: note
::: title
注意
:::

免费 Google 账户每天最多可获取 100 张免费图片。如需更多图片,需要进行计费升级。  
::::

### Google API 控制台 {#product_images/google-api-dashboard}

1. 访问 [Google Cloud Platform API & Services](https://console.developers.google.com/) 页面以生成 Google Custom Search API 凭证。使用 Google 账户登录后,勾选 `Terms of Service` 并点击 `Agree and Continue`
2. 在此处选择(或创建)一个 API 项目来保存凭证。先为项目取一个易记的 `Project Name`,如有需要选择 `Location`,随后点击 `Create`
3. 在左侧侧栏选择 `Credentials`,点击 `Create Credentials`,从下拉菜单中选择 `API key`
   ![API & Services page on Google Cloud Platform.](product_images/credentials-api-key.png){.align-center}

4. 系统会弹出 `API key created` 窗口,显示自定义的 `API key`。复制并保存 `Your API key`,稍后将会用到。复制完毕后点击 `Close` 关闭弹窗。

   ![The API key created pop-up window that appears.](product_images/api-key-pop-up.png){.align-center}

5. 在本页面搜索 **Custom Search API** 并选择它。

   ![Search bar containing "Custom Search API" on Google Cloud Platform.](product_images/custom-search-api-search-bar.png){.align-center}

6.`Custom Search API` 页面,点击 `Enable` 启用该 API。

   ![\"Custom Search API\" page with Enable button highlighted on Google Cloud Platform.](product_images/gcp-custom-search-api-page.png){.align-center}

### Google Programmable Search 仪表盘 {#product_images/google-pse-dashboard}

1. 前往 [Google Programmable Search Engine](https://programmablesearchengine.google.com/),点击任意 `Get started` 按钮。若未登录,请使用 Google 账户登录。

   ![Google Programmable Search Engine page with the Get Started buttons.](product_images/google-pse-get-started.png){.align-center}

2.`Create a new search engine` 表单中填写搜索引擎名称及搜索范围,并务必勾选 `Image Search``SafeSearch`
   ![Create new search engine form that appears with search engine configurations.](product_images/create-new-search.png){.align-center}

3. 点击 `Create` 验证表单。

4. 系统会显示页面标题 `Your new search engine has been created`
   ![The Your New Search Engine Has Been Created page that appears with copy code.](product_images/new-search-engine-has-been-created.png){.align-center}

5. 在该页面点击 `Customize`,打开 `Overview --> Basic` 页面。复制 `Search engine ID` 字段中的 ID,此 ID 将用于 Odoo 配置。

   ![Basic overview page with search engine ID field.](product_images/basic-overview-search-engine-id.png){.align-center}

### Odoo {#product_images/setup-in-odoo}

1. 在 Odoo 数据库中,进入 `Settings` 应用,滚动到 `Integrations` 区块。勾选 `Google Images` 复选框后点击 `Save`
   ![The Google Images setting in the Odoo Settings app page.](product_images/google-images-setting.png){.align-center}

2. 再次返回 `Settings` 应用,同样滚动到 `Integrations` 区块,在 `Google Images` 功能下方的字段中填写前面获取的 `API Key``Search Engine ID`
3. 点击 `Save`
## 使用 Google Custom Search API 在 Odoo 中获取产品图片 {#product_images/get-product-images}

在 Odoo 中为产品添加图片可以在任意产品或产品变体页面完成。只要能够打开产品页面的 Odoo 应用(如 *Sales*、*Inventory* 等)均可操作。

以下是使用 *Google Custom Search API* 在 Odoo *Sales* 应用中为产品分配图片的逐步指南:

1.*Sales* 应用中进入 `Products` 页面(路径:Sales app → Products → Products),或进入 `Product Variants` 页面(路径:Sales app → Products → Product Variants)。

2. 选中需要添加图片的产品。

   :::: note
   ::: title
   注意
   :::

   仅处理 **有条形码且没有图片** 的产品(或产品变体)。

   若选中的产品拥有多个变体,则符合上述条件的每个变体都会被处理。  
   :::

3. 在产品页面点击 `Action ⚙️ (gear)` 图标,在弹出菜单中选择 `Get Pictures from Google Images`
   ![The Get Pictures from Google Images option from the Action drop-down menu in Odoo.](product_images/get-pictures-from-google-action.png){.align-center}

4. 在出现的弹窗中点击 `Get Pictures`
   ![The pop-up that appears in which the user should click Get Picture in Odoo Sales.](product_images/click-get-picture-from-pop-up.png){.align-center}

5. 点击后,图片会逐步显示。

   :::: note
   ::: title
   注意
   :::

   首批 10 张图片会立即获取。若选择的图片超过 10 张,其余图片会作为后台任务逐步获取。

   后台任务每分钟大约处理 100 张图片。如果达到 Google 配额(免费或付费计划),后台任务会暂停 24 小时,然后继续上一次中断的工作。  
   :::

::: seealso
[Create, modify, or close your Google Cloud Billing account](https://cloud.google.com/billing/docs/how-to/manage-billing-account)
:::

[SUMMARY]

# 使用 Google 图片的产品图像
## 配置
### Google API 控制台
- 生成 API 密钥并保存
- 启用 Custom Search API
### Google Programmable Search Engine
- 创建搜索引擎并勾选图片搜索、SafeSearch
- 获取搜索引擎 ID
### Odoo 设置
- 在 Settings → Integrations 中启用 Google Images
- 填入 API Key 与 Search Engine ID 并保存
## 在 Odoo 中获取产品图片
- 打开产品或产品变体页面
- 选择有条形码且无图片的记录
- 使用 “从 Google 图片获取” 操作
- 首批 10 张图片即时返回,其余通过后台任务逐步获取