[英]How can I access Google App Engine endpoints API from Python application with use OAuth?
How can I access Google App Engine endpoints API for Python (not web, android, ios)? 如何访问适用于Python(而非Web,Android,iOS)的Google App Engine端点API?
I read this tutorial but it not explains it enough to understand this. 我阅读了本教程,但对它的解释不足以理解这一点。
As I found on serve side I can use such code to identify user: 正如我在服务端发现的那样,我可以使用以下代码来识别用户:
@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 API示例的完整代码
How can I connect from Python client to this API and call 'hellogreeting/authed' with authentication current_user != None
. 如何从Python客户端连接到此API,并使用身份验证
current_user != None
调用“问候/已身份验证”。
Can you share some code how to do it? 您可以分享一些代码怎么做吗?
app_id = 'xxx'
user = 'xxx'
password = 'xxx'
callAPI(app_id, user, password, 'hellogreeting/authed')
You need to configure your App Engine instance to be able to serve your API. 您需要配置App Engine实例以能够提供您的API。 I would recommend you create a separate module dedicated to your API, like explained in these docs: https://developers.google.com/appengine/docs/python/endpoints/api_server .
我建议您创建一个专用于您的API的单独模块,如以下文档中所述: https : //developers.google.com/appengine/docs/python/endpoints/api_server 。
Once everything is correctly set up on the server side, you can call your API using something like: http://your-module.your-app.appspot.com/_ah/spi/hellogreeting/authed
. 在服务器端正确设置完所有内容后,您可以使用类似以下的命令来调用API:http:
http://your-module.your-app.appspot.com/_ah/spi/hellogreeting/authed
。
If you're using the development server, things are a little bit different for accessing modules, but once you know which port number the App Engine development server has assigned to your API module, you can reach it locally using: http://localost:<api_module_port_#>/_ah/spi/hellogreeting/authed
. 如果您使用的是开发服务器,则在访问模块时会有些不同,但是一旦知道App Engine开发服务器为API模块分配了哪个端口号,就可以使用以下本地方法访问它:
http://localost:<api_module_port_#>/_ah/spi/hellogreeting/authed
Hope this helped. 希望这会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.