Php 已成功接收Google calendar API同步消息,但未收到有关日历更改的通知

Php 已成功接收Google calendar API同步消息,但未收到有关日历更改的通知,php,api,push-notification,google-calendar-api,Php,Api,Push Notification,Google Calendar Api,我成功地建立了一个通知通道,并从Google Calendar V3 API接收到第一条消息同步消息,该消息表示它可以找到我的回调url等。但是,当我更改日历时,它不会向我的回调地址发出任何通知 x-Goog-Channel-ID:20fdedbf0-a845-11e3-1515e2-0800200c9a6671111 X-Goog-Channel-Expiration:Tue, 18 Mar 2014 15:48:34 GMT X-Goog-Resource-State:sync X-Goog

我成功地建立了一个通知通道,并从Google Calendar V3 API接收到第一条消息同步消息,该消息表示它可以找到我的回调url等。但是,当我更改日历时,它不会向我的回调地址发出任何通知

x-Goog-Channel-ID:20fdedbf0-a845-11e3-1515e2-0800200c9a6671111
X-Goog-Channel-Expiration:Tue, 18 Mar 2014 15:48:34 GMT
X-Goog-Resource-State:sync
X-Goog-Message-Number:1
X-Goog-Resource-ID:WSX5G_51Ds8C7ZADf8Yemzhfego
X-Goog-Resource-URI:https://www.googleapis.com/calendar/v3/calendars/primary/events?alt=json
//我请求的代码

session_start();
require_once(dirname(__FILE__)."/../includes/GoogleAPI/Google_Client.php");
require_once(dirname(__FILE__)."/../includes/GoogleAPI/contrib/Google_CalendarService.php");

$this->client = new Google_Client();
$this->client->setApplicationName("Test Application");

$this->client->setUseObjects(true);
if (isset($_SESSION['gapi_token'])) {

    $this->client->setAccessToken($_SESSION['gapi_token']);

} else {

    $key = file_get_contents(dirname(__FILE__). '/../includes/' . $this->key_file);
    $this->client->setAssertionCredentials( new Google_AssertionCredentials( $this->service_account_name , array( 'https://www.googleapis.com/auth/calendar' ), $key ));

    $_SESSION['gapi_token'] = $this->client->getAccessToken();
} 
$this->client->setClientId($this->client_id);
$cal = new Google_CalendarService($this->client);

$event = new Google_Event();
$event->setSummary('Appointment Test'); 
$event->setLocation('Amsterdam');     

/* Start Date
*/
$start = new Google_EventDateTime();
$start->setDateTime('2014-03-10T19:00:00.000+01:00'); 
$event->setStart($start);

/* Eind date
*/
$end = new Google_EventDateTime();
$end->setDateTime('2014-03-10T22:00:00.000+01:00'); 
$event->setEnd($end);

/* Voeg gasten toe
*/
$attendee1 = new Google_EventAttendee();
$attendee1->setEmail('[myemailadress]');
$attendees = array($attendee1);
$event->attendees = $attendees;

$createdEvent = $cal->events->insert('primary', $event);

echo "<pre>Event ID : '" . $this->client->getAccessToken() . "'</pre>";


//Part that creates the notification channel
$token = $this->client->getAccessToken();
$token_decode = json_decode($token);

$calendar = 'primary';
$url = sprintf("https://www.googleapis.com/calendar/v3/calendars/%s/events/watch", $calendar);
$fields = json_encode(array(
    'id'        => "20fdedbf0-a845-11e3-1515e2-0800200c9a6671111", 
    'type'      => "web_hook",
    'address'   => 'https://www.[mydomain].nl/apiero/calendar.push.notifications.php'
));

/* setup POST headers */
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: Bearer ' . $token_decode->access_token;

/* send POST request */
$channel = curl_init();
curl_setopt($channel, CURLOPT_HTTPHEADER, $headers);
curl_setopt($channel, CURLOPT_URL, $url);
curl_setopt($channel, CURLOPT_RETURNTRANSFER, true);
curl_setopt($channel, CURLOPT_POST, true);
curl_setopt($channel, CURLOPT_POSTFIELDS, $fields);
curl_setopt($channel, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($channel, CURLOPT_TIMEOUT, 3);
$response = curl_exec($channel);
curl_close($channel);

$response = json_decode($response);

dump($response);

有人能帮我解决这个问题吗?

让我试试。您需要将监视请求中的“主要”替换为您希望获得通知的实际电子邮件地址,因此:


你能解决这个问题吗?我目前遇到这个问题。
stdClass Object
(
[kind] => api#channel
[id] => 20fdedbf0-a845-11e3-1515e2-0800200c9a6671111
[resourceId] => WSX5G_51Ds8C7ZADf8Yemzhfego
[resourceUri] => https://www.googleapis.com/calendar/v3/calendars/primary/events?alt=json
[expiration] => 1395159757000
)
$calendar = 'youremailhere@google.com';// remove primary string that was here
$url =     sprintf("https://www.googleapis.com/calendar/v3/calendars/%s/events/watch", $calendar);
   $fields = json_encode(array(
   'id'        => "20fdedbf0-a845-11e3-1515e2-0800200c9a6671111", 
   'type'      => "web_hook",
   'address'   => 'https://www.[mydomain].nl/apiero/calendar.push.notifications.php'
));