一天以来,我一直试图了解this的工作方式,现在我完全感到困惑。
这是我的目标(非常简单):当我收到新电子邮件时,对URL进行GET请求。
如何设置其余部分?我不知道现在该怎么办。
答案 0 :(得分:1)
我执行了一个 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
}
}