【问题标题】:Adding event to Google Calendar将活动添加到 Google 日历
【发布时间】:2012-04-22 11:03:03
【问题描述】:

我们正在使用 API Google 开发应用程序。在这个过程中,我们遇到了一些困难。

我们使用了此页面“code.google.com/p/google-api-php-client/”上的 php-sdk 我们使用了 Google 日历服务。我们遵循位于此处的文档:“developers.google.com/google-apps/calendar/v3/reference/”部分日历和事件。

源数据: - 允许访问位于此处“code.google.com/apis/console/”的 Google 日历服务 - 请求所需的用户授权(基于此处的文档:“developers.google.com/google-apps /calendar/v3/reference/events/insert)"

任务:将事件添加到日历。 行动:我们将 Post-Request 发送到 https://www.googleapis.com/calendar/v3/calendars/{calendarId}/events?calendarId={calendarId}&alt=json&key={API Key}

请求正文:

{

"\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"

}

注意:为了形成事件对象,我们使用了代码(与这里的示例开发者.google.com/google-apps/calendar/v3/reference/events/insert 部分示例中的示例相同)

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

来自 API 的回答(带有标头)

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"

 } 

}

【问题讨论】:

    标签: google-calendar-api


    【解决方案1】:

    玩弄这个工具。我有同样的问题。它适用于资源管理器,但不适用于我的 Rails 服务器。

    https://developers.google.com/google-apps/calendar/v3/reference/events/insert#try-it

    【讨论】:

      【解决方案2】:

      您提到的文档(http://developers.google.com/google-apps/calendar/v3/reference)记录了 Google 日历 API 的 REST 接口。然而,PHP 客户端库的工作方式有所不同,遗憾的是几乎没有文档记录。

      我使用了 Google 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 的所有其他文档(AFAIK)只能在 Google_CalendarService 类的 cmets 中找到:https://code.google.com/p/google-api-php-client/source/browse/trunk/src/contrib/Google_CalendarService.php

      您可以使用以下代码向 Google 日历添加新活动:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-17
        • 1970-01-01
        • 1970-01-01
        • 2013-01-28
        • 2014-03-31
        相关资源
        最近更新 更多