2012-04-10 154 views
0

我們正在使用API​​ Google開發應用程序。在這個過程中,我們遇到了一些困難。將活動添加到Google日曆

我們使用的PHP SDK,它是此頁「code.google.com/p/google-api-php-client/」我們用谷歌日曆服務上。我們遵循以下文檔:「developers.google.com/google-apps/calendar/v3/reference/」部分日曆和活動。

源數據: - 訪問被允許設在這裏「code.google.com/apis/console/」 - 更換用戶授權請求谷歌日曆服務(基於位置的文檔:「developers.google.com/google-應用程序/日曆/ V3 /參考/事件/插入)」

任務:添加事件日曆。 行動:我們發送請求後到https://www.googleapis.com/calendar/v3/calendars/ {calendarId} /事件calendarId = {calendarId} & ALT = JSON &鍵= {API密鑰}

請求正文:?

{ 

"\u0000*\u0000__creatorType":"EventCreator", 

"\u0000*\u0000__creatorDataType":"", 

"\u0000*\u0000__organizerType":"EventOrganizer", 

"\u0000*\u0000__organizerDataType":"", 

"\u0000*\u0000__attendeesType":"EventAttendee", 

"\u0000*\u0000__attendeesDataType":"array", 

"\u0000*\u0000__startType":"EventDateTime", 

"\u0000*\u0000__startDataType":"", 

"start":{ 

"date":"", 

"timeZone":"Europe\/Moscow", 

"dateTime":"2012-0408T12:00:00+04:00" 

}, 

"location":"sdasdwqwqesaddsa", 

"\u0000*\u0000__originalStartTimeType":"EventDateTime", 

"\u0000*\u0000__originalStartTimeDataType":"", 

"\u0000*\u0000__gadgetType":"EventGadget", 

"\u0000*\u0000__gadgetDataType":"", 

"description":"sadasdzxczxcasdsaweqqwasd", 

"\u0000*\u0000__extendedPropertiesType":"EventExtendedProperties", 

"\u0000*\u0000__extendedPropertiesDataType":"", 

"\u0000*\u0000__endType":"EventDateTime", 

"\u0000*\u0000__endDataType":"", 

"end":{ 

"date":"", 

"timeZone":"Europe\/Moscow", 

"dateTime":"2012-04-08T19:00:00+04:00" 

}, 

"\u0000*\u0000__remindersType":"EventReminders", 

"\u0000*\u0000__remindersDataType":"", 

"summary":"wqeqwesadasewqe" 

} 

注意:要形成事件的對象,我們使用碼(同實施例在這裏developers.google.com/google-apps/calendar/v3/reference/events/insert部分的實施例)從API

Result: API returns an error with code 400 (Bad Request) 

回答(帶頭)

HTTP/1.1 400 Bad Request Content-Type: application/json; charset=UTF-8 Date: Fri, 06 Apr 2012 05:53:55 GMT Expires: Fri, 06 Apr 2012 05:53:55 GMT Cache-Control: private, max-age=0 X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=block Server: GSE Transfer-Encoding: chunked 

{ "error": { 

"errors": [ 

{ "domain": "global", 

"reason": "badRequest", 

"message": "Bad Request" } 

], 

"code": 400, 

"message": "Bad Request" 

} 

} 

回答

0

你提到的文檔(上http://developers.google.com/google-apps/calendar/v3/reference)記錄了REST接口與谷歌日曆API。但是,PHP客戶端庫的工作方式不同,不幸的是幾乎沒有記錄。

我用包含在谷歌PHP API客戶機(https://code.google.com/p/google-api-php-client/source/browse/trunk/examples/calendar/simple.php)的樣品。您需要在Google的API控制檯中生成一個oAuth客戶端ID,祕密密鑰等(這些工作原理在API客戶端的文檔中有記錄)。

關於日曆PHP API的所有其他文檔(據我所知)才得以在Google_CalendarService類的評論發現:

https://code.google.com/p/google-api-php-client/source/browse/trunk/src/contrib/Google_CalendarService.php

您可以使用下面的代碼添加一個新的事件,谷歌日曆

$event = new Google_Event(); 

// Event title and location 
$event->setSummary('Event title'); 
$event->setLocation('Some location'); 

// Start and end time of the event 
$start = new Google_EventDateTime(); 
$start->setDateTime('2013-08-08T14:00:00+02:00'); 
$event->setStart($start); 

$stop = new Google_EventDateTime(); 
$stop->setDateTime('2013-08-08T16:00:00+02:00'); 
$event->setEnd($stop); 

// Insert event in calendar. 
// 'primary' may be replaced with a full @group.calendar.google.com calendar ID. 
$createdEvent = $cal->events->insert('primary', $event);