为 Python 设置 Google API 客户端库需要完成以下步骤:

  1. 配置本地开发环境

    1. 下载Python对应的 Google API client libraries

    2. 配置Python虚拟环境Python virtual environment

    3. 创建一个~/shopping-samples/content/目录

      这个路径,以及在步骤 5 中创建的 merchant-info.json 文件的文件名,在步骤 7 中下载的 Content API samples 目录中的 python/shopping/content/common.py 文件中定义。

  2. 下载content-api

    1. Merchant Center 的“设置”菜单中,选择 Content API
    2. 点击认证
    3. 添加 API key
    4. 保存 content-api.json 到本地
  3. 将下载的 content-api.json 改名为 service-account.json

    此文件名在 _constants.py 文件中定义,该文件位于第 7 步中下载的 Content API 示例目录中的 python/shopping/content/ 中。

  4. service-account.json 文件移动到主目录/shopping-samples/content/

  5. 在主目录/shopping-samples/content/ 中,创建一个空的 Merchant-info.json 文件, 并添加以下文本。

    1
    2
    3
    4
    5
    {
    "merchantId": your Merchant Center merchant ID,
    "accountSampleUser": "the email address associated with your Merchant Center account"
    }

  6. 克隆(或下载并解压) googleads/googleads-shopping-samples GitHub repo 到电脑上的任何位置, 它不一定在主目录或~/shopping-samples/content/。

  7. 安装所需依赖,导航到googleads-shopping-samples/python/并运行:

    1
    pip install -r requirements.txt

现在已经配置好了 Python API 客户端, 接下来可以和the Content API一起进行 API 调用。