Based on this answer by @bossylobster, I have successfully implemented a cron job that connects with the GMail API. Currently I have the user_id and email address in my code, however I am building an app where it should run through a list of users.
Problem in that case is that when I run a loop on the CredentialsModel, I don't have the user's email address. Since I am using the User model from webapp 2 (based on this tutorial), I also can't look this ID up anywhere (as far as I know).
If I could somehow retrieve the email address with the user_id and credentials, or save the email address and user_id in the user model at the moment the permissions are given... What would be the best way to handle this?
My code for getting authorization:
http = httplib2.Http(memcache)
service = discovery.build("gmail", "v1", http=http)
decorator = OAuth2Decorator(client_id=settings.CLIENT_ID,
client_secret=settings.CLIENT_SECRET,
scope=settings.SCOPE)
class getPermissions(webapp2.RequestHandler):
@decorator.oauth_aware
def get(self):
template_values = {
'url': decorator.authorize_url(),
'has_credentials': decorator.has_credentials()
}
self.response.out.write(template.render('templates/auth.html', template_values))