簡體   English   中英

如何使用OAuth從Python應用程序訪問Google App Engine端點API?

[英]How can I access Google App Engine endpoints API from Python application with use OAuth?

如何訪問適用於Python(而非Web,Android,iOS)的Google App Engine端點API?

我閱讀了本教程,但對它的解釋不足以理解這一點。

正如我在服務端發現的那樣,我可以使用以下代碼來識別用戶:

@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,))

API示例的完整代碼

如何從Python客戶端連接到此API,並使用身份驗證current_user != None調用“問候/已身份驗證”。

您可以分享一些代碼怎么做嗎?

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

您需要配置App Engine實例以能夠提供您的API。 我建議您創建一個專用於您的API的單獨模塊,如以下文檔中所述: https : //developers.google.com/appengine/docs/python/endpoints/api_server

在服務器端正確設置完所有內容后,您可以使用類似以下的命令來調用API:http: http://your-module.your-app.appspot.com/_ah/spi/hellogreeting/authed

如果您使用的是開發服務器,則在訪問模塊時會有些不同,但是一旦知道App Engine開發服務器為API模塊分配了哪個端口號,就可以使用以下本地方法訪問它: http://localost:<api_module_port_#>/_ah/spi/hellogreeting/authed

希望這會有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM