How can i get user's email, using tornado.auth.TwitterMixin?

python

#1

How can i get user’s email, using tornado.auth.TwitterMixin? I send request for get user’s emails

Example:

class TwitterLoginHandler(tornado.web.RequestHandler,
                          tornado.auth.TwitterMixin):
    @tornado.gen.coroutine
    def get(self):
        if self.get_argument('oauth_token', None):
            user = yield self.get_authenticated_user(

            )
            access = yield self.twitter_request(
                '/account/verify_credentials',
                args=['include_email', True],
                access_token=user['access_token']
            )
            print(access['name'])
            print(access)
            # self.set_secure_cookie('user', user['email'])
            # self.redirect(self.get_argument('next', '/'))
        else:
            yield self.authorize_redirect()

#2

I had 1 mistake: twitter_request don’t have attribute “args”. If you want to get user’s email, you need to set attribute “include_email=True”, so twitter_request will be looks like:

access = yield self.twitter_request(
                '/account/verify_credentials',
                include_email= True,
                access_token=user['access_token']
            )

#3

Glad you figured this out, and thanks for sharing the answer with the community!


#4