Gmail Push notification PHP backend error

314 Views Asked by At

This is my code for gmail watch request push notification

define('SCOPES', implode(' ', array(
        Google_Service_Gmail::MAIL_GOOGLE_COM)
));
$this->client = new Google_Client();
$this->client->setApplicationName(APPLICATION_NAME);
$this->client->setScopes(SCOPES);
$this->client->setAuthConfig(CLIENT_SECRET_PATH);
$this->client->setAccessType('offline');
$this->client->setApprovalPrompt('force');

$credentialsPath = CREDENTIALS_PATH;

if(!file_exists($credentialsPath)){
    redirect('gmail');
}
$accessToken = json_decode(file_get_contents($credentialsPath), true);
$this->token = $accessToken['access_token'];

$this->client->setAccessToken($accessToken);
if ($this->client->isAccessTokenExpired()) {
    $refreshTokenSaved = $this->client->getRefreshToken();
    $this->client->fetchAccessTokenWithRefreshToken($refreshTokenSaved);
    //$client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
    file_put_contents($credentialsPath, json_encode($this->client->getAccessToken()));
}
$service = new Google_Service_Gmail($this->client);
$watchreq = new Google_Service_Gmail_WatchRequest();
$watchreq->setLabelIds(array('INBOX'));
$watchreq->setTopicName('projects/composed-field-201410/topics/wooglobe');
$msg = $service->users->watch('me', $watchreq);

i am getting this error Type: Google_Service_Exception

Message: { "error": { "errors": [ { "domain": "global", "reason": "backendError", "message": "Backend Error" } ], "code": 500, "message": "Backend Error" } }

Filename: D:\xampp\htdocs\viralgreats\admin\vendor\google\apiclient\src\Google\Http\REST.php

Line Number: 118

0

There are 0 best solutions below