1

这是我的 gmail 手表请求推送通知代码

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);

我收到此错误类型:Google_Service_Exception

消息:{“错误”:{“错误”:[{“域”:“全局”,“原因”:“后端错误”,“消息”:“后端错误”}],“代码”:500,“消息” :“后端错误”}}

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

行号:118

4

0 回答 0