为 Python 设置 Google API 客户端库需要完成以下步骤:
配置本地开发环境
下载
Python
对应的 Google API client libraries配置
Python
虚拟环境Python virtual environment创建一个
~/shopping-samples/content/
目录这个路径,以及在步骤 5 中创建的
merchant-info.json
文件的文件名,在步骤 7 中下载的 Content API samples 目录中的python/shopping/content/common.py
文件中定义。
下载
content-api
- 在 Merchant Center 的“设置”菜单中,选择 Content API
- 点击认证
- 添加
API
key - 保存
content-api.json
到本地
将下载的 content-api.json 改名为
service-account.json
此文件名在
_constants.py
文件中定义,该文件位于第 7 步中下载的 Content API 示例目录中的python/shopping/content/
中。将
service-account.json
文件移动到主目录/shopping-samples/content/
。在主目录
/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"
}克隆(或下载并解压) googleads/googleads-shopping-samples GitHub repo 到电脑上的任何位置, 它不一定在主目录或~/shopping-samples/content/。
安装所需依赖,导航到
googleads-shopping-samples/python/
并运行:1
pip install -r requirements.txt