设置客户端库

我们建议您使用 Google API 客户端库来设置 Content API for Shopping。本指南以 Python Content API 客户端库为例,但支持多种热门的编程语言,并简化了身份验证、发送请求和解析响应等常见 API 任务。如需设置其他语言的客户端库,请参阅 GitHub 上 googleads/googleads-shopping-samples 代码库中的语言的 README.md

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

  1. 为客户端库的配置和身份验证文件创建目录。在主目录中,创建以下目录:

    ~/shopping-samples/content/

  2. 如需下载您的服务帐号凭据,请完成以下步骤:

    1. Merchant Center设置菜单中,选择 Content API
    2. 点击身份验证
    3. 点击 [+] CREATE API KEY
    4. 如果出现提示,请阅读并接受服务条款协议。

    系统会自动下载新密钥。

  3. 将下载的凭据文件重命名为 service-account.json

  4. service-account.json 文件移动到 home directory/shopping-samples/content/

  5. home directory/shopping-samples/content/ 中,创建一个空的 merchant-info.json 文件。

  6. merchant-info.json 中,添加以下文本:

    {
    "merchantId": your Merchant Center merchant ID,
    "accountSampleUser": "the email address associated with your Merchant Center account"
    }
    
  7. googleads/googleads-shopping-samples GitHub 代码库克隆(或下载并解压缩)到计算机上的任何位置;不必位于主目录或 ~/shopping-samples/content/ 中。

  8. 如果您已下载并解压缩代码库,而不是进行克隆,请将解压缩的目录重命名为 googleads-shopping-samples

  9. 如需安装所需的示例依赖项,请在终端窗口中转到 googleads-shopping-samples/python/,然后运行以下命令:

    pip install -r requirements.txt
    

现在,您已为 Python 配置了 Google API 客户端库,并可与 Content API 配合使用。在下一部分中,您将创建并发送插入新产品的请求。