【问题标题】:How to call Google Talent Solution api from Google App Engine (Python)如何从 Google App Engine (Python) 调用 Google Talent Solution api
【发布时间】:2018-09-13 15:14:50
【问题描述】:

我想使用 Google Talent Solution (GTS)。

set-up docs 解释了如何使用服务帐户设置标准环境 App Engine 项目。我在我的 App Engine 项目中启用了 GTS,启用了数据记录,并在启用 GTS 时创建的App Engine default service account 中添加了一个Service Account Token Creator - [app-id]@appspot.gserviceaccount.com

我为 Python AppEngine 项目使用了 read the docs,但它使用了 deprecated API oauth2client,而我正在尝试使用 google_auth(我已经安装并出售了 google_apigoogle_auth

在我的供应商appengine_config.py

from google.appengine.ext import vendor
import os

google_api_path = "%s%s" % (os.path.dirname(os.path.realpath(__file__)), '/applications/[app-id]/modules/google_api')

vendor.add(google_api_path)

google_auth = "%s%s" % (os.path.dirname(os.path.realpath(__file__)), '/applications/[app-id]/modules/google')

vendor.add(google_auth)

我将 google_auth 安装到名为 google 的目录中。在一个目录路径/applications/[app-id]/modules/ 中,它可以与 Python 框架 Web2py 很好地配合使用。

我的代码:

from google.auth import app_engine
credentials = app_engine.Credentials()
print(credentials.token)

唉,credentials.tokenNone

在所有这些设置、配置和代码中,我错过了什么?

【问题讨论】:

  • 我错过了设置a security requirement object and a security definitions object in your OpenAPI configuration file to support authentication of a calling service。试试这个。
  • 添加了 OpenAPI 配置文件后,对 app_engine.Credentials() 的调用仍会返回令牌成员设置为 None 的对象

标签: google-app-engine google-api


【解决方案1】:

可能是因为 oauth2client 已被弃用。来自googleapis/oauth2client

注意:oauth2client 现已弃用。库中将不再添加任何功能,核心团队正在拒绝支持。我们 建议您使用google-authoauthlib。更多细节 关于弃用,请参阅oauth2client deprecation

但我看到google-auth 使用gRPC,至少不久前它与标准环境GAE 应用程序不兼容,请参阅GRPC and types import error in App Engine Datastore,所以YMMV。

【讨论】:

  • 谢谢。这是非常有建设性的。
  • 我已经根据我取得的进展重写了这个问题。 google_auth 已安装并可调用,但未返回凭据
【解决方案2】:

进行更改(我已添加到我的问题中)后,调用工作!

因为我使用的服务帐户 credentials.token 是 None 并且我可以继续调用 Google Talent Solution 来添加例如公司。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-07
    相关资源
    最近更新 更多