getting 403 error on watch request on gmail API ph

2019-06-13 16:15发布

问题:

I am trying to make watch request to gmail API but getting 403 error every time :- Error sending test message to Cloud PubSub projects/projectId/topics/topic : User not authorized to perform this action.

<?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);
标签: php gmail-api