部署使用 google-api-python-客户端库作为 Google 云函数的 Python 脚本

Deploying Python script that use google-api-python-client library as Google Cloud Function

我创建了一个 Python 脚本,它使用 google-api-python-客户端库 (https://github.com/googleapis/google-api-python-client) 从我的数据库中提取数据DFA 帐户。

我想将这个脚本部署到 Google Cloud Scheduler,这样我就可以每天 运行 这个脚本。当我部署函数时,我收到一条错误消息“ModuleNotFoundError:没有名为“googleapiclient”的模块。

在我将“googleapi客户端”添加到 requirements.txt 并再次部署后,我收到一个新错误,提示找不到 googleapi要添加的客户端库。

请问是否可以在Google云平台下安装googleapi客户端库?

是的,可以在 GCP 中安装和使用 googleapiclient 库。在您的 python 代码中导入 Google API Client 时使用 googleapiclient module

import googleapiclient

然后在 requirements.txt

中添加 google-api-python-client
# Function dependencies, for example:
# package>=version
google-api-python-client

你可以检查这个sample code from github that uses the googleapiclient module and this requirements.txt