如何使用OAuth从Python应用程序访问googleappengine端点API?

2024-10-03 17:17:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我如何访问googleappengine endpoints API for Python(而不是web、android、ios)?在

我读了这篇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并使用身份验证调用“hellogreeting/authend”current_user != None

你能分享一些代码怎么做吗?在

^{pr2}$

Tags: 代码noneapiwebmessageforemailcurrent
1条回答
网友
1楼 · 发布于 2024-10-03 17:17:24

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

一旦在服务器端正确设置了所有内容,您就可以使用如下命令调用API:http://your-module.your-app.appspot.com/_ah/spi/hellogreeting/authed。在

如果您使用的是开发服务器,那么访问模块的情况会有所不同,但是一旦您知道appengine开发服务器分配给API模块的端口号,就可以使用:http://localost:<api_module_port_#>/_ah/spi/hellogreeting/authed在本地访问它。在

希望这有帮助。在

相关问题 更多 >