`
greatghoul
  • 浏览: 143206 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

在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()

   
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics