我们建议使用 Google API 客户端库来设置 Content API for Shopping。本指南以 Python Content API 客户端库为例,但该客户端库适用于许多主流编程语言,并简化了身份验证、发送请求和解析响应等常见 API 任务。如果在设置其他语言的客户端库方面需要帮助,请参阅 GitHub 上的 googleads/googleads-shopping-samples 代码库中该语言的 README.md。
如需设置适用于 Python 的 Google API 客户端库,请完成以下步骤:
为客户端库的配置和身份验证文件创建一个目录。在您的主目录中,创建以下目录:
~/shopping-samples/content/
如需下载服务帐号凭据,请完成以下步骤:
- 在 Merchant Center 的设置菜单中,选择 Content API。
- 点击身份验证。
- 点击 [+] 创建 API 密钥。
- 如果出现提示,请阅读并接受服务协议条款。
系统会自动下载新密钥。
将下载的凭据文件重命名为 service-account.json。
将 service-account.json 文件移至 home directory/shopping-samples/content/。
在 home directory/shopping-samples/content/ 中,创建一个空的 merchant-info.json 文件。
在 merchant-info.json 中,添加以下文本:
{ "merchantId": your Merchant Center merchant ID, "accountSampleUser": "the email address associated with your Merchant Center account" }
将 googleads/googleads-shopping-samples GitHub 代码库克隆(或下载并解压缩)到计算机上的任意位置;该代码库不必位于您的主目录或 ~/shopping-samples/content/ 中。
如果您下载并解压缩了代码库,请不要克隆,而是将解压缩的目录重命名为 googleads-shopping-samples。
要安装所需的示例依赖项,请在终端窗口中转到 googleads-shopping-samples/python/,然后运行以下命令:
pip install -r requirements.txt
现在,您已经配置了适用于 Python 的 Google API 客户端库,可以用于 Content API 了。在下一部分中,您将创建并发送插入新商品的请求。