我认为您可能会混淆 OAuth 2.0 装饰器与其他两种方法的作用。
OAuth 2.0 装饰器并非特定于您的应用程序,如果您想为用户获取 OAuth 2.0 凭据,然后使用这些凭据与 Google API 进行通信,则可以使用它。
另外两种只是从 App Engine 设置的会话 cookie 中获取用户信息的方法。
如果你真的想要一个装饰器,你会使用login_required
,记录在这里:
https://developers.google.com/appengine/docs/python/tools/webapp/utilmodule
在指定之间没有一种最佳方法app.yaml
,检查是否users.get_current_user
is None
或使用@login_required
在指定的处理程序上。
您想要使用的三个不同时间的粗略近似如下:
1)如果您希望用户登录,但不需要知道具体用户,请使用login: required
in app.yaml
.
2) 如果想了解用户,但如果用户未登录也有后备,请使用users.get_current_user
并根据用户或用户调整您的行为None
如果这是返回值。
3) 如果您想了解用户并始终有一个登录用户,请使用@login_required
.
UPDATE:
(基于对需求的进一步解释。)由于您始终希望用户登录并始终需要他们的 OAuth 2.0 凭据,因此您应该始终使用decorator.oauth_required
.
至于使用API,只需谷歌日历API可以与google-api-python-client
图书馆。这Google Apps 配置 API is a 谷歌数据API,而日历 API 是基于发现的API.
因此,您需要使用gdata-python-client
library使用配置 API。您需要手动从oauth2client.client.OAuth2Credentials object to a gdata.gauth.OAuth2Token反对对任一者使用相同的令牌。
使用时OAuth2Decorator
,您将能够访问一个实例oauth2client.client.OAuth2Credentials
via decorator.credentials()
.
第二次更新:
我最近added对此的支持gdata-python-client
.
from gdata.gauth import OAuth2TokenFromCredentials
auth_token = OAuth2TokenFromCredentials(decorator.credentials())
auth_token.authorize(client)
该实现允许两个令牌/凭证对象decorator.credentials()
and auth_token
无论您更改哪个对象的值,都保持同步。