Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get recent 10 emails using Gmail-api?

For now, I can use gmail api to get all UNREAD emails or all emails in INBOX.

GMAIL.users().messages().list(userId='me', labelIds=['UNREAD', 'INBOX']).execute()

Because getting all the emails could be annoying, I was wondering is it possible to get only the recent 10 UNREAD emails from gmail api?

Thanks for any hint that will allow me to do such thing.

like image 763
American curl Avatar asked Aug 22 '17 01:08

American curl


People also ask

How do I automate Gmail API?

Enable Gmail API So you need to go to https://console.developers.google.com to activate the API access of the email that you will use in your project. Click ENABLE APIS AND SERVICES. It will take you to the search page. There, you need to search for GMAIL.

What can we do with Gmail API?

The Gmail API is a RESTful API that can be used to access Gmail mailboxes and send mail. For most web applications the Gmail API is the best choice for authorized access to a user's Gmail data and is suitable for various applications, such as: Read-only mail extraction, indexing, and backup.


1 Answers

The documentation tells us that we need to pass maxResults and set it to 10:

GMAIL.users().messages().list(userId='me', labelIds=['UNREAD'], maxResults=10).execute()
like image 176
Tholle Avatar answered Sep 18 '22 14:09

Tholle