【问题标题】:How can I access Google App Engine endpoints API from Python application with use OAuth?如何使用 OAuth 从 Python 应用程序访问 Google App Engine 端点 API?
【发布时间】:2014-06-14 12:57:37
【问题描述】:

如何访问适用于 Python(不是 Web、android、ios)的 Google App Engine 端点 API?

我读过这个tutorial,但它的解释不足以理解这一点。

正如我在服务端发现的,我可以使用这样的代码来识别用户:

@endpoints.method(message_types.VoidMessage, Greeting,
                  path='hellogreeting/authed', http_method='POST',
                  name='greetings.authed')
def greeting_authed(self, request):
    current_user = endpoints.get_current_user()
    email = (current_user.email() if current_user is not None
             else 'Anonymous')
    return Greeting(message='hello %s' % (email,))

Full code of API example

如何从 Python 客户端连接到此 API 并使用身份验证 current_user != None 调用“hellogreeting/authed”。

你能分享一些代码吗?

app_id = 'xxx'
user = 'xxx'
password = 'xxx'
callAPI(app_id, user, password, 'hellogreeting/authed')

【问题讨论】:

    标签: python google-app-engine google-oauth google-cloud-endpoints google-cloud-platform


    【解决方案1】:

    您需要配置您的 App Engine 实例才能为您的 API 提供服务。我建议您创建一个专用于您的 API 的单独模块,如以下文档中所述:https://developers.google.com/appengine/docs/python/endpoints/api_server

    在服务器端正确设置所有内容后,您可以使用以下方式调用您的 API:http://your-module.your-app.appspot.com/_ah/spi/hellogreeting/authed

    如果您使用的是开发服务器,访问模块的情况会有所不同,但是一旦您知道 App Engine 开发服务器为您的 API 模块分配了哪个端口号,您就可以使用以下方式在本地访问它:@987654323 @。

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2012-07-19
      • 1970-01-01
      • 1970-01-01
      • 2015-11-15
      • 2018-06-24
      • 1970-01-01
      • 2014-07-30
      • 2011-08-27
      • 1970-01-01
      相关资源
      最近更新 更多