简体   繁体   English

如何完成此Google Calendar Api v3-FreeBusy PHP-示例?

[英]How to finish this Google Calendar Api v3 - FreeBusy PHP - example?

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. 我想使用google api v3 freebusy(php)查找三个日历的免费freebusy信息,但是我找不到我代码的正确结尾。 I want to access the "calendars - busy" values of the $freebusy-response. 我想访问$ 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. 由于在api引用处没有示例代码,并且我在网络上找不到任何有效的代码(但是很多人要求这样做),你们是我最后一次希望运行此代码。

...
$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: 这是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
            }
        ]
        }
    }
    }

Here's my resolution (only the setItems part of your code is wrong): 这是我的解决方法(仅代码的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);

Hope this helps, cheers! 希望这会有所帮助,加油!

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

I am working in Grails and this works for me. 我在Grails工作,这对我有用。

def heute = new DateTime(false, new Date().time, null)
def heutePlusEinJahr = new DateTime(false, (new Date() + 365).time, null)

println heute
println heutePlusEinJahr
Events feed = servicecalendar.events().list(calendarId).setTimeMin(heute).setTimeMax(heutePlusEinJahr).execute();
return feed

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM