本文介绍了如何完成这个谷歌日历API V3 - FreeBusy PHP - 的例子吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用谷歌的API V3 freebusy(PHP)找到我的三个日历的免费freebusy信息,但我不找到正确的结局我的code。我想访问日历 - 忙。在$ freebusy响应值

由于是在API参考无例 - code和我不能在网路上找到任何工作code(但很多人问它)你们是我最后的希望得到这个运行

  ...
$ =服务新Google_CalendarService($客户端); //成功连接
$ freebusy =新Google_FreeBusyRequest();
$ freebusy-> setTimeMin('2013-07-08T08:00:00.000-07:00');
$ freebusy-> setTimeMax('2013-07-08T10:00:00.000-07:00');
$ freebusy-> setTimeZone('欧洲/柏林);
$ 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 = $服务 - > freebusy->查询($ freebusy);回声$ createdReq-> getKind(); //作品
回声$ createdReq-> getTimeMin(); //作品
回声$ createdReq-> getTimeMax(); //作品
$ S = $ createdReq-> getCalendars($ diekalender);
的print_r($ S,真正的); //不显示任何东西
    //需要:日历的值:{(键):{忙 - 一个或所有日历的数组

这是API参考说,有关的反应是什么:

  {
    种:历#freeBusy
    时间min:日期时间,
    timeMax:日期时间,
    组:{
        (键):{
        错误:
            {
            域:字符串,
            原因:字符串
            }
        ]
        日历:
            串
        ]
        }
    },
    日历:{
        (键):{
        错误:
            {
            域:字符串,
            原因:字符串
            }
        ]
        忙: [
            {
            开始:日期时间,
            结束:日期时间
            }
        ]
        }
    }
    }


解决方案

下面是我的分辨率(只有你的code的setItems一部分是错误的):

  $ freebusy_req =新Google_FreeBusyRequest();
$ freebusy_req-> setTimeMin(日期(日期时间:: ATOM,的strtotime($ date_from)));
$ freebusy_req-> setTimeMax(日期(日期时间:: ATOM,的strtotime($ DATE_TO)));
$ freebusy_req-> setTimeZone(美国/芝加哥);
$项目=新Google_FreeBusyRequestItem();
$本期特价货品> SETID('{} calendarId');
$ freebusy_req-> setItems(数组($项目));
$查询= $服务 - > freebusy->查询($ freebusy_req);

希望这有助于,干杯!

I want to use the google api v3 freebusy (php) to find free freebusy-information of three of my calendars, but I dont find the correct ending to my code. I want to access the "calendars - busy" values of the $freebusy-response.

Since there is no example-code at the api-reference and i couldnt find any working code on the web (but lots of people asking for it) you guys are my last hope to get this running.

...
$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

This is what the API-reference says about the response:

  {
    "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
            }
        ]
        }
    }
    }
解决方案

Here's my resolution (only the setItems part of your code is wrong):

$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);

Hope this helps, cheers!

这篇关于如何完成这个谷歌日历API V3 - FreeBusy PHP - 的例子吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 02:26
查看更多