0
votes

I tried to understand how this works since more than a day, and I'm totally confused right now.

Here is my (very simple) goal: make a GET request on a URL when I receive a new email.

  • I have created a topic as they asked (named new-email)
  • I have a subscription in that topic (named new-email-inbox), with delivery type push, and setting my endpoint URL.
  • I gave my subscription authorization to this account: [email protected] (Editor & Editor Pub/Sub)

How do I set up the rest ? I don't understand what to do now..

1
The next step is using a Gmail Client and let a code running listenning to the Users: watch endpoint as the docs say. What programming language are you using? - alberto vielma
I use php. I did it with a cronjob, asking everyday to watch one endpoint. The thing is, as I need to use it all the time, I don't understand why I can't set that watch request forever the first time and i'm done with it. Or even set that up in the Google API manager by enabling it here (and disable it if needed). - Antoine Nedelec
you can't set it for ever because you are using the HTTP protocol when calling the endpoint, which is an stateless protocol that needs to be closed eventually. That's how REST APIs architectures work. Anyways, I'm glad you could find a workaround for your issue. - alberto vielma

1 Answers

1
votes

I did a Symfony4 command, executed everyday like a cron:

class WatchGoogleClient extends Command {

    private $kernel;
    private $gmailService;

    public function __construct(GmailService $gmailService, Kernel $kernel)
    {
        parent::__construct();
        $this->gmailService = $gmailService;
        $this->kernel = $kernel;
    }

    protected function configure()
    {
        $this->setName('app:watch-google-client')
            ->setDescription('watch-google-client')
            ->setHelp('Reset the google watch timer');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        // This getClient function is basically what is given by the google API tutorial
        $client = $this->gmailService->getClient($this->kernel);
        $service = new \Google_Service_Gmail($client);
        $watchreq = new \Google_Service_Gmail_WatchRequest();
        $watchreq->setLabelIds(array('INBOX'));
        $watchreq->setTopicName('YOUR_TOPIC_NAME');
        $msg = $service->users->watch('me', $watchreq);

        var_dump($msg);
        // DO WHAT YOU WANT WITH THIS RESPONSE BUT THE WATCH REQUEST IS SET
    }
}