【发布时间】:2015-04-12 07:16:24
【问题描述】:
我正在尝试使用 PHP 和 V3 api 为 Google 日历设置推送通知。
我已获得 Auth2.0 权限,并且能够从我的应用程序在 google 上创建事件。现在我想知道用户何时对谷歌日历进行了任何更改(CRUD 操作)。
这是我的代码:
private $imageService;
public $google_client;
public $google_calendar;
public function __construct()
{
$this->imageService = new ImageService();
$this->google_client = new Google_Client();
$this->google_client->setApplicationName($_ENV['GOOGLE_APP_NAME']);
$this->google_client->setDeveloperKey($_ENV['GOOGLE_API_KEY']);
$this->google_client->setClientId($_ENV['CLIENT_ID']);
$this->google_client->setClientSecret($_ENV['CLIENT_SECRET']);
$this->google_client->setAccessType('offline');
$this->google_client->setIncludeGrantedScopes(true);
$this->google_client->setScopes(array('email', 'profile', 'https://www.googleapis.com/auth/plus.me', 'https://www.googleapis.com/auth/calendar'));
$this->google_calendar = new Google_Service_Calendar($this->google_client);
}
public function googleCalendarWatch($uuid){
$channel = new Google_Service_Calendar_Channel($this->google_client);
$channel->setId($uuid);
$channel->setType('web_hook');
$channel->setAddress("https://example.com/google/googleNotifications");
$channel->setExpiration("1919995862000");
$this->google_calendar->events->watch('primary', $channel);
}
这是输出:
Google_Service_Calendar_Channel Object (
[internal_gapi_mappings:protected] => Array ( )
[address] =>
[expiration] => 1426272395000
[id] => aee2b430-34bf-42bc-a597-ada46db42799
[kind] => api#channel
[params] =>
[payload] =>
[resourceId] => 51IKGpOwCJ6EMraQMUc1_04MODk
[resourceUri] => https://www.googleapis.com/calendar/v3/calendars/primary/events?key=AIzaSyBFUvq3OZO6ugAKvz7l8NgLS0V6DUJq8Vc&alt=json
[token] =>
[type] =>
[modelData:protected] => Array ( )
[processed:protected] => Array ( ) )
到目前为止我还不知道为什么address返回null,也许这就是问题所在。但我不知道如何解决它。
还阅读此内容:#26730263 并查看我自己的代码并没有太大区别。
我做了谷歌所说的所有事情,注册域、添加凭据、api 密钥、允许推送域等等。
【问题讨论】:
-
您将用户重定向到谷歌服务器以获取身份验证令牌的部分在哪里?
-
@mathieu- 都是 wrkg...我在我的 webhook url 中获得点击,但它只是空白...我如何从 webhook 中选择响应。
-
您的用户需要经过身份验证才能添加新的 webhook
-
@MathieudeLorimier- 我已完成身份验证并拥有经过验证的 webhook。我得到了如上所示的东西,但我的问题是当我更新谷歌日历中的数据时,我没有得到任何数据(来自 webhook)。
-
@Sinto 根据第一个答案(在上面链接的问题中),您没有在 webhook 中获得任何数据,您只会收到更改的通知。然后,您需要找出发生了什么变化。或者你是说你的钩子根本没有被调用?
标签: php calendar google-calendar-api google-api-php-client