在GAE中使用Google Account | #python #gae

要在Python版SDK中使用Google Account,需要导入:
from google.appengine.api import users


生成登陆地址:
users.create_login_url(登陆后跳转到的地址)

生成注销链接:
users.create_logout_url(注销后跳转到的地址)

获取用户邮箱:
user.email()

一个简单的登陆\注销的例子:
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class MainPage(webapp.RequestHandler):
def get(self):
user = users.get_current_user()

# Not signed in
if not user:
msg = ('Welcome! <a href="%s">Sign In</a>'
% users.create_login_url(self.request.path))
# Signed in.
else:
msg = ('Welcome, %s! <a href="%s">Sign out</a>'
% (user.email(), users.create_logout_url(self.request.path)))

# Write the content
self.response.headers['Content-Type'] = 'text/html'
self.response.out.write(msg)

application = webapp.WSGIApplication([('/', MainPage)],debug = True)

def main():
run_wsgi_app(application)

if __name__ == '__main__':
main()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值