我正在尝试向gmail API发出监视请求,但每次都会收到403错误: - 向Cloud PubSub项目/ projectId / topics / topic发送测试消息时出错:用户未被授权执行此操作。
<?php
require_once __DIR__ . '/vendor/autoload.php';
$client = new Google_Client();
$client->setAuthConfig('/opt/lampp/htdocs/gmail-api/client_secret.json');
$client->setScopes(array("https://mail.google.com/", "https://www.googleapis.com/auth/gmail.compose", "https://www.googleapis.com/auth/gmail.modify", "https://www.googleapis.com/auth/gmail.readonly", "https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/pubsub"));
$client->setIncludeGrantedScopes(true);
$client->setAccessType("offline");
$service = new Google_Service_Gmail($client);
$watchreq = new Google_Service_Gmail_WatchRequest();
$watchreq->setLabelIds(array('INBOX'));
$watchreq->setTopicName('projects/Id/topics/tid');
$msg = $service->users->watch('me', $watchreq);