【发布时间】:2016-02-03 17:16:09
【问题描述】:
我正在为这个网站工作,该网站允许您在线安排与教师就不同主题的教学课程。我们最近为用户添加了链接他们的谷歌日历的选项,以便他们安排的每个新教学课程都会自动在他们的日历上创建。
这很好用。当访问令牌过期时,我有刷新令牌(离线访问)。所以这一切都在正常工作。
问题是,当教师和用户都链接了他们的日历,并且我的函数尝试为两者创建相同的事件时,第一个事件被创建(比如说,为用户),但是时间到了为老师创建相同的事件,它失败并返回 404“notFound”,就好像它没有找到日历一样。
我的猜测是我使用的是同一个 google 客户端对象,一旦设置了访问令牌,您可能无法更改它们。我试过unset() 或$this->gclient = null,但它不起作用。
我正在使用 CodeIgniter,所以我为谷歌日历 API 创建了一个库。在我的代码中,我做了这样的事情:
...
if ($user->hasGoogleCalendar) {
$this->addEventToCalendar($user, $event);
}
if ($teacher->hasGoogleCalendar) {
$this->addEventToCalendar($teacher, $event);
}
...
function addEventToCalendar($user, $event) {
//the constructor for gcalendar creates the google client
$this->load->library("gcalendar");
//this verifies the access token, refreshes if necessary and
//creates the event
$this->gcalendar->addEventToCalendar($user->access_token, $user->calendarId, $event);
}
所以这第一次有效(对于 $user),但随后对于 $teacher 失败(404 notFound)。如果我颠倒第一个 if 语句(这样老师是第一位的,然后是用户),那么老师会在他/她的日历上获得事件而学生不会。
所以基本上问题是我无法为同一个 Google 客户端或类似的东西设置新的 access_token。我尝试卸载库并再次加载,但没有找到使其工作的方法。
我也试过了:
$this->load->library("gcalendar", NULL, "gcalendar1");
$this->load->library("gcalendar", NULL, "gcalendar2");
但它是一样的,现在我有 2 个不同的对象 $this->gcalendar1 和 $this->gcalendar2 但发生同样的错误。
对于我的图书馆,我使用的是Google Api PHP client
有什么想法吗?
【问题讨论】:
标签: php codeigniter api calendar google-calendar-api