Search code examples
phppush-notificationgmailgmail-apigoogle-cloud-pubsub

Gmail Push Notification using PHP


Reading the Gmail API docs, I noticed that the Gmail API provides a way to push notification to a backend endpoint URL. The idea is to call process() in our backend when a user receive a new email (avoiding the pulling method).

I created a new suscription (Cloud Pub/Sub API) and I tested publishing a new message from the Cloud Platform Console. The API works like expected. But now, I don't know how to notify to Gmail API to start to watch changes of the user's INBOX. We can use watch() and stop() in Python, but what about PHP?

enter image description here


Solution

  • Google discovery service APIs are simple rest APIs. You can use them with any language capable of preforming a HTTP Post and HTTP Get.

    Google is very good about making things easer for developers so they have created a number of open source client libraries to help developers. The Google APIs PHP Client library is one such library. it handles most of the hard work for you.

    I would check out the PHP Quickstart tutorial first then move on to User.watch after you have your authentication flow working.