如何设置 gmail 推送通知

How to set up gmail push notification

一天多以来,我一直试图了解 this 的工作原理,但现在我完全糊涂了。

这是我的(非常简单的)目标:当我收到一封新邮件时,在 URL 上发出 GET 请求。

如何设置其余部分?现在不知道怎么办..

我做了一个 Symfony4 命令,像 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
    }
}