Receive notification of Gmail only when a new message arrives

I am trying to make an application that will find out if the recipient answered my email address with a GMAIL push notification. It works well, but the problem is that I am notified of any changes in my gmail.

Here is the code I used

request = { 'labelIds': ['UNREAD'], 'topicName': topic, 'labelFilterAction': 'include' } service.users().watch(userId=user.google_id, body=request).execute() 

then I tried to use 'labelFilterAction': 'exclude'

 system_labels = ['CATEGORY_UPDATES', 'UNREAD', 'DRAFT', 'CATEGORY_PROMOTIONS', 'INBOX', 'CATEGORY_SOCIAL', 'CATEGORY_PERSONAL', 'CATEGORY_FORUMS', 'TRASH', 'CHAT', 'IMPORTANT', 'SENT', 'STARRED', 'SPAM'] system_labels.remove('UNREAD') request = { 'labelIds': system_labels, 'topicName': topic, 'labelFilterAction': 'exclude' } service.users().watch(userId=user.google_id, body=request).execute() 

with this, I do not receive any notice at all. any suggestion?

+7
gmail gmail api
source share
1 answer

python working code

 credentials = get_credentials(email) http = credentials.authorize(httplib2.Http()) service = discovery.build('gmail', 'v1', http=http) request = { 'labelIds': ['CATEGORY_PERSONAL'], 'topicName': 'projects/myproject/topics/getNotification', 'labelFilterAction': 'exclude' } service.users().watch(userId='me',body=request).execute() 
0
source share

All Articles