I have decorator:
http = httplib2.Http()
service = discovery.build('gmail', 'v1', http=http)
# Creating decorator for OAuth2 account.
decorator = appengine.oauth2decorator_from_clientsecrets(
CLIENT_SECRETS,
scope='https://www.googleapis.com/auth/gmail.readonly',
message=MISSING_CLIENT_SECRETS_MESSAGE)
And class that use it:
class CSVGeneratorHandler(webapp2.RedirectHandler):
@decorator.oauth_required
def get(self):
http = decorator.http()
first_messages = service.users().messages().list(userId='me').execute(http=http)
template = JINJA_ENVIRONMENT.get_template('templates/success.html')
self.response.write(template.render({}))
That works great.
But when I try to move API request service.users().messages().list(userId='me').execute(http=http) to the task (with deferred.defer(get_mails)) I got an error: "Login required".
I understand that get_mails function must to receive context or/and credentials from the main program. But I don't understand how to do that.
Can someone help me?