GMAIL API doesn't accept most queries (GAE Python)
Question: I'm trying to fetch all sent messages for the last 3 months, using a Google
App Engine app on Python. For some reason though it doesn't accept most of the
queries that I enter. It returns results for a simple string, but if I enter
something like "after:2015/01/20", or "newer_than:3m" it gives me the
following error:

    
    
    AttributeError: 'Resource' object has no attribute 'messages'
    

I have no clue where this could be coming from. My current code for the
request is:

    
    
    import webapp2, httplib2
    from dateutil.relativedelta import *
    
    from oauth2client.appengine import OAuth2Decorator
    from apiclient import discovery, errors
    from oauth2client import client
    from google.appengine.api import memcache
    
    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 retrieveMessages(webapp2.RequestHandler):
    
      @decorator.oauth_required
      def get(self):
        try:
            user = 'someone@gmail.com'
            after = (datetime.datetime.now()+relativedelta(months=-3)).strftime("%Y/%m/%d")
            query = 'after:'+after
            http = decorator.http()
            response = service.users().messages().list(userId=user, labelIds='SENT', q=query, maxResults=1000).execute(http=http)
            messages = []
            if 'messages' in response:
                messages.extend(response['messages'])
    
            while 'nextPageToken' in response:
              page_token = response['nextPageToken']
              response = service.users().messages().list(userId=user, labelIds='SENT', q=query, pageToken=page_token).executehttp=http(http=http)
              messages.extend(response['messages'])
    
            return messages
        except errors.HttpError, error:
            print 'An error occurred: %s' % error
            if error.resp.status == 401:
              # Credentials have been revoked.
              # TODO: Redirect the user to the authorization URL.
              raise NotImplementedError()
    


Answer: Shouldn't this snippet inside the while loop:

    
    
    response = service.messages()...
    

be

    
    
    response = service.users().messages()...
    

