简体   繁体   English

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

[英]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.

相关问题 如何从python Google App Engine端点中的方法返回对象? - How can I return an object from a method in python google app engine endpoints? 如何将对谷歌应用程序引擎 flask 端点的访问限制为仅应用程序代码(或应用程序引擎服务帐户) - How to limit access to google app engine flask endpoints to just application code (or app engine service accounts) Google App Engine-端点API-从另一个App Engine应用程序使用-python - Google App Engine - Endpoints API - Consuming from another App Engine App -python 如何通过Google App Engine Python将OAuth用于用户名和密码 - How to use OAuth for username and password with Google App Engine Python 使用App Engine SDK在localhost中部署我的Google端点python应用程序时出错 - Error when I am deploying my google cloud endpoints python application in localhost with App Engine SDK Google App Engine Python的Flickr OAuth - Flickr OAuth from Google App Engine Python 如何使用Google App Engine? - How can I use google app engine? Python:如何使用请求库访问 Google App Engine 上托管的 Flask RestPlus API? - Python: How to Use Requests Library to Access Flask RestPlus API hosted on Google App Engine? 如何访问用于在Python App Engine中存储数据的低级API - How to access lowlevel API for storing data in Google App Engine for python Google App Engine端点api在localhost中不起作用 - Google app engine endpoints api not working in localhost
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM