3

我想使用 google api v3 freebusy (php) 来查找我的三个日历的免费 freebusy 信息,但我没有找到我的代码的正确结尾。我想访问 $freebusy-response 的“日历 - 忙碌”值。

由于 api-reference 中没有示例代码,而且我在网络上找不到任何工作代码(但很多人要求它),所以你们是我运行它的最后希望。

...
$service = new Google_CalendarService($client); // successfully connected
$freebusy = new Google_FreeBusyRequest();
$freebusy->setTimeMin('2013-07-08T08:00:00.000-07:00');
$freebusy->setTimeMax('2013-07-08T10:00:00.000-07:00');
$freebusy->setTimeZone('Europe/Berlin');
$freebusy->setGroupExpansionMax(10);
$freebusy->setCalendarExpansionMax(10);
$mycalendars= array("my_calendar_id1@developer.gserviceaccount.com","my_calendar_id2@group.calendar.google.com","my_calendar_id3@group.calendar.google.com");
$freebusy->setItems = $mycalendars;
$createdReq = $service->freebusy->query($freebusy);

echo $createdReq->getKind(); // works
echo $createdReq->getTimeMin(); // works
echo $createdReq->getTimeMax(); // works
$s = $createdReq->getCalendars($diekalender);  
Print_r($s, true); // doesn't show anything
    // needed: the value of "calendars": { (key): { "busy" - array of one or all calendars

这就是 API 参考关于响应的内容:

  {
    "kind": "calendar#freeBusy",
    "timeMin": datetime,
    "timeMax": datetime,
    "groups": {
        (key): {
        "errors": [
            {
            "domain": string,
            "reason": string
            }
        ],
        "calendars": [
            string
        ]
        }
    },
    "calendars": {
        (key): {
        "errors": [
            {
            "domain": string,
            "reason": string
            }
        ],
        "busy": [
            {
            "start": datetime,
            "end": datetime
            }
        ]
        }
    }
    }
4

2 回答 2

6

这是我的解决方案(只有代码中的 setItems 部分是错误的):

$freebusy_req = new Google_FreeBusyRequest();
$freebusy_req->setTimeMin(date(DateTime::ATOM, strtotime($date_from)));
$freebusy_req->setTimeMax(date(DateTime::ATOM, strtotime($date_to)));
$freebusy_req->setTimeZone('America/Chicago');
$item = new Google_FreeBusyRequestItem();
$item->setId('{calendarId}');
$freebusy_req->setItems(array($item));
$query = $service->freebusy->query($freebusy_req);

希望这会有所帮助,干杯!

于 2013-08-01T10:19:34.360 回答
0
$service = new Google_CalendarService($client); // successfully connected
$freebusy = new Google_FreeBusyRequest();
$freebusy->setTimeMin('2013-07-08T08:00:00.000-07:00');
$freebusy->setTimeMax('2013-07-08T10:00:00.000-07:00');
$freebusy->setTimeZone('Europe/Berlin');
$freebusy->setGroupExpansionMax(10);
$freebusy->setCalendarExpansionMax(10);
$mycalendars = array( array("id"=>"my_calendar_id1@developer.gserviceaccount.com"), array("id"=>"my_calendar_id2@group.calendar.google.com"), array("id"=>"my_calendar_id3@group.calendar.google.com"));
$freebusy->setItems($mycalendars);
$createdReq = $service->freebusy->query($freebusy);
于 2014-04-22T10:29:18.847 回答