2013-07-09 121 views
1

我想使用google api v3 freebusy(php)來查找我的三個日曆的免費freebusy信息,但是我找不到我的代碼的正確結尾。我想訪問$ freebusy-response的「日曆 - 繁忙」值。如何完成此Google Calendar Api v3 - FreeBusy PHP - 示例?

由於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("[email protected]","[email protected]","[email protected]"); 
$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 
      } 
     ] 
     } 
    } 
    } 

回答

2

這裏是我的分辨率(只有你的代碼的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); 

希望這幫助,歡呼!

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"=>"[email protected]"), array("id"=>"[email protected]"), array("id"=>"[email protected]")); 
$freebusy->setItems($mycalendars); 
$createdReq = $service->freebusy->query($freebusy); 
-2

我在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 
+2

請勿發佈代碼圖片。寫在這裏,讓人們可以看到它,並在需要時複製它。此外,請解釋您的答案如何解決問題(編輯答案並添加更多詳細信息) – Takarii

相關問題