Как настроить gmail pu sh уведомление - PullRequest
0 голосов
/ 05 марта 2020

Я пытался понять, как это работает более суток, и сейчас я совершенно сбит с толку.

Вот моя (очень простая) цель: make запрос GET на URL, когда я получаю новое письмо.

  • Я создал topi c, как они просили (названный new-email) )
  • У меня есть подписка в этом топи c (с именем new-email-inbox ), с типом доставки pu sh и настройку URL-адреса моей конечной точки.
  • Я дал авторизацию подписки для этой учетной записи: gmail-api-push@system.gserviceaccount.com ( Editor & Editor Pub / / Sub )

Как настроить остальные? Я не понимаю, что теперь делать ..

1 Ответ

1 голос
/ 09 марта 2020

Я выполнил команду 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
    }
}
...