Search code examples
node.jsgoogle-oauthgmail-api

Nodejs Gmail OAuth API to get Users.threads: list


I want to get list of threads after a specific datetime, but couldn't find any way to do it. I have stored the updated datetime in the database according to the last time the Gmail API was used to fetch the list of threads. Then using that updated time I want to retrieve the list further.


Solution

  • The Gmail API allows you to list threads/messages after a specific timestamp with second accuracy.

    Let's say you want to list threads with messages received after Friday, 22-Jul-16 00:00:00 UTC, you would write after:1469145600 in the q-parameter.

    Request

    GET https://www.googleapis.com/gmail/v1/users/me/threads?q=after%3A1469145600&access_token={YOUR_ACCESS_TOKEN}
    

    Response

    {
     "threads": [
      {
       "id": "1561153ce695b9ab",
       "snippet": "Infinite Elgintensity has uploaded Gym Idiots - Spread Eagle Rows & Mike O'Hearn 585-Lb. Squat A montage of gym fails with... Infinite Elgintensity has uploaded Gym Idiots - Spread Eagle Rows",
       "historyId": "895071"
      }
     ],
     "resultSizeEstimate": 1
    }