Reputation: 45
I am using the php watch commant:
try {
$service = new Google_Service_Calendar($this->gapi->client);
$channel = new Google_Service_Calendar_Channel($this->gapi->client);
$uuid = '27baf74c-59****************';
$channel->setId($uuid);
$channel->setType('web_hook');
$channel->setToken($uuid);
$channel->setAddress('https://*********.com/calendar_webhook');
$watchEvent = $service->events->watch('primary',$channel);
print_r($watchEvent);
} catch (Exception $e) {
print_r($e->getMessage());
}
after that i get response like this for $watchEvent
Google_Service_Calendar_Channel Object
(
[internal_gapi_mappings:protected] => Array
(
)
[address] =>
[expiration] => 1471667969000
[id] => 27baf74c-59d*****************
[kind] => api#channel
[params] =>
[payload] =>
[resourceId] => Ga-R5***************
[resourceUri] => https://www.googleapis.com/calendar/v3/calendars/primary/events?key=AIzaS*********************&alt=json
[token] => 27baf74c-5****************
[type] =>
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
)
But in my notification url I don't get any message when changes in my calendar. Am I missing something!? In my response address parameter is empty. is there any issue. I have done all url verification in google. Please help me
Upvotes: 4
Views: 1327
Reputation: 4950
You must implement Watch
method. To set up a notification channel for messages about changes to a particular resource, send a POST
request to the watch
method for the resource.
Each notification channel is associated both with a particular user and a particular resource. A watch request will not be successful unless the current user owns or has permission to access this resource.
Request:
https://www.googleapis.com/apiName/apiVersion/resourcePath/watch
Start watching for changes to a collection of events on a given calendar:
POST https://www.googleapis.com/calendar/v3/calendars/example.com/events/watch
Authorization: Bearer auth_token_for_current_user
Content-Type: application/json
{
"id": "01234567-89ab-cdef-0123456789ab", // Your channel ID.
"type": "web_hook",
"address": "https://example.com/notifications", // Your receiving URL.
...
"token": "target=myApp-myCalendarChannelDest", // (Optional) Your channel token.
"expiration": 1426325213000 // (Optional) Your requested channel expiration time.
}
}
Response:
{
"kind": "api#channel",
"id": "01234567-89ab-cdef-0123456789ab"", // ID you specified for this channel.
"resourceId": "o3hgv1538sdjfh", // ID of the watched resource.
"resourceUri": "https://www.googleapis.com/calendar/v3/calendars/example.com/events", // Version-specific ID of the watched resource.
"token": "target=myApp-myCalendarChannelDest", // Present only if one was provided.
"expiration": 1426325213000, // Actual expiration time as Unix timestamp (in ms), if applicable.
}
After creating a new notification channel to watch a resource, the Google Calendar API sends a sync message to indicate that notifications are starting. The X-Goog-Resource-State
HTTP header value for these messages is sync. Because of network timing issues, it is possible to receive the sync message even before you receive the watch
method response.
Upvotes: 1