为 Python 设置 Google API 客户端库
January 15, 2022
1091
为 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
现在已经配置好了 Python API 客户端, 接下来可以和the Content API
一起进行 API 调用。
- 本文作者:Wenhua Chen
- 本文链接:https://wenhuachen.com/2022/01/15/%E4%B8%BA-Python-%E8%AE%BE%E7%BD%AE-Google-API-%E5%AE%A2%E6%88%B7%E7%AB%AF%E5%BA%93/index.html
- 版权声明:本博客所有文章均采用 BY-NC-SA 许可协议,转载请注明出处!