【问题标题】:Connect a Google Cloud function in Python to the Google Search Console API将 Python 中的 Google Cloud 函数连接到 Google Search Console API
【发布时间】:2021-09-16 17:26:30
【问题描述】:

我想在 Python 中创建一个 Google Cloud 函数来

  • 连接到 Google Search Console API
  • 提取数据
  • 通过管道将其导入 BigQuery

我可以找到各种代码示例来通过 OAuth、密钥等进行身份验证和连接,但是这些似乎都适用于在 本地 运行的 Python 脚本,而不是在云中。 (我需要它在云中运行,无人值守)。

Google 文档说,在 Cloud Function 中,可以使用“应用程序默认凭据 (ADC) 自动查找您的服务帐户凭据”自动进行身份验证。

此代码示例例如连接到 Cloud Storage 并对其进行身份验证:

def implicit():
    from google.cloud import storage

    # If you don't specify credentials when constructing the client, the
    # client library will look for credentials in the environment.
    storage_client = storage.Client()

    # Make an authenticated API request
    buckets = list(storage_client.list_buckets())
    print(buckets)

但是,我找不到任何有关如何创建将通过 ADC 机制进行身份验证的 Google Search Console 客户端的文档。

请帮忙!

【问题讨论】:

  • 你好@little_edian。以下任何一个答案是否helped you

标签: python google-cloud-functions google-search-api google-search-console


【解决方案1】:
【解决方案2】:

根据Search API documnetationOAuth 2.0是唯一办法:

您的应用程序必须使用 OAuth 2.0 来授权请求​​。不支持其他授权协议。

Cloud Storage 有方便的 Python(以及其他语言)API,它正在处理这个 ADC 身份验证。说到Google Search API,我不是很熟悉,但是我查过example code。在示例中,如果我理解正确,身份验证是在 api 之外使用 oauth2client 完成的。

但是,我敢肯定,您可以使用 Cloud Function 中的 OAuth 2.0 来执行此操作,原因与您在本地执行此操作的原因完全相同。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-27
    • 1970-01-01
    相关资源
    最近更新 更多