Is there a way to map GAE user object and Google+

2019-07-18 05:55发布

As mentioned here, for default authentication using python users API an object will be returned based on user's email. When user_id() is called over the object a unique id is returned, which is of course not a Google+ user id.


import webapp2
from google.appengine.api import users

class MainPage(webapp2.RequestHandler):
        def get(self):
            user = users.get_current_user()
            if user:
                if users.is_current_user_admin():
                    utype = "Admin"
                else:
                    utype = "Normal" 
                self.response.headers['Content-Type'] = 'text/html'
                self.response.out.write('Hello, ' + user.nickname() + ' Userid: ' + user.user_id() + ' User Type: ' + utype)
            else:
                self.redirect(users.create_login_url(self.request.uri))

app = webapp2.WSGIApplication([
                                ('/', MainPage)
                            ], debug=False)

Basically, I need the plus id to retrieve some user details. (via HTTP GET)

Is there any available package in AppEngine API that can provide me with google plus id for a logged in user's email?

Or should I move on to OAuth 2 for authentication purpose?

I have already completed 50% based on users API, so any help regarding the same will be appreciated.

1条回答
时光不老,我们不散
2楼-- · 2019-07-18 06:30

Yes, using their user.email()

To access properties of their Google+ profile you will need to use the Google APIs Client Library for Python https://developers.google.com/api-client-library/python/start/installation

查看更多
登录 后发表回答