Push notification 如何设置gmail推送通知
一天多以来,我一直在努力理解它是如何工作的,现在我完全搞不清楚 这是我(非常简单)的目标:当我收到新电子邮件时,对URL发出GET请求。Push notification 如何设置gmail推送通知,push-notification,gmail,gmail-api,google-cloud-pubsub,Push Notification,Gmail,Gmail Api,Google Cloud Pubsub,一天多以来,我一直在努力理解它是如何工作的,现在我完全搞不清楚 这是我(非常简单)的目标:当我收到新电子邮件时,对URL发出GET请求。 我已经按照他们的要求创建了一个主题(名为新邮件) 我在该主题(名为“新电子邮件收件箱”)中有一个订阅,具有传递类型推送,并设置我的端点URL 我已将订阅授权授予此帐户:gmail api-push@system.gserviceaccount.com(编辑和编辑发布/订阅) 我如何设置其余的?我不知道现在该怎么办。我做了一个Symfony4命令,每天都像c
- 我已经按照他们的要求创建了一个主题(名为新邮件)
- 我在该主题(名为“新电子邮件收件箱”)中有一个订阅,具有传递类型推送,并设置我的端点URL
- 我已将订阅授权授予此帐户:gmail api-push@system.gserviceaccount.com(编辑和编辑发布/订阅)
我如何设置其余的?我不知道现在该怎么办。我做了一个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
}
}
下一步是使用Gmail客户端,让运行的代码监听端点。你用什么编程语言?我用php。我做了一个cronjob,要求每天观察一个端点。问题是,因为我需要一直使用它,我不明白为什么我不能在第一次永远设置那个手表请求,我已经完成了。甚至可以在Google API管理器中通过在此处启用(并在需要时禁用)来设置它。您不能永远设置它,因为您在调用端点时使用的是HTTP协议,这是一个最终需要关闭的无状态协议。RESTAPI体系结构就是这样工作的。不管怎样,我很高兴你能找到解决问题的办法。