谷歌日历API第3版 - 不创建事件(服务器到服务器身份验证) [英] Google Calendar API v3 - Not Creating Event (Server-to-Server Authentication)

查看:215
本文介绍了谷歌日历API第3版 - 不创建事件(服务器到服务器身份验证)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以周围挖了几个小时后,我在一个解决方案的损失。我试图创建我使用谷歌的日历API的V3主日历事件,但我没有遇到预期的行为。

我用在这种情况下服务器到服务器身份验证。要做到这一点,我创建服务帐户凭据,感动我的密钥对到同一目录作为我的测试脚本,并设置谷歌日历API为开开发者控制台中。

下面你会找到问题code。

(如谷歌所提到的)预期的结果是,在被成功地创建一个事件/添加到日历,事件对象或数组(你的愿望)将被退回。在这两种情况下,收到的事件对象或数组,但事件不会在日历显示。如果我尝试访问与所创建的事件数据集提供了htmlLink,我收到一条错误消息这个事件不存在。

我想像的,因为我得到一个事件对象返回了所有必要的细节,这是成功的;但没有雪茄。我试图与事件的知名度的属性玩了(将其设置为公共),但仍没有运气。

我真的AP preciate,如果有人可以在这里帮我一把。

[code]

  require_once __DIR__。 /GoogleAPI/Google_Client.php';
require_once __DIR__。 /GoogleAPI/contrib/Google_CalendarService.php';$ =谷歌新Google_Client();$ google-> setUseObjects(TRUE);
$ google-> SETCLIENTID(%my_client_id%);
$ google-> setAssertionCredentials(
    新Google_AssertionCredentials(
        %my_client_id_email%​​,
        阵列(
            https://www.googleapis.com/auth/calendar',
            https://www.googleapis.com/auth/calendar.readonly
        )
        的file_get_contents(__ DIR__。/google_key.p12')
    )
);$ =服务新Google_CalendarService($谷歌);$事件=新Google_Event();$事件 - > setSummary('考试排期');
$事件 - >的setLocation('试验');
$事件 - > setVisibility(公共);$开始=新Google_EventDateTime();
$开始 - > setDateTime('2014-03-28T10:00:00.000-05:00');
$事件 - > setStart($开始);$结束=新Google_EventDateTime();
$端值> setDateTime('2014-03-28T10:30:00.000-05:00');
$事件 - > SETEND($结束);$ createdEvent = $服务 - >及事件─GT;插入('主',$事件,阵列('maxAttendees'=大于1,'sendNotifications'=> FALSE));后续代码var_dump($ createdEvent);

=============================================== ==============================

[结果]

 对象(Google_Event)#20(56){
  [anyoneCanAddSelf] =>
  空值
  [__attendeesType:保护] =>
  串(20)Google_EventAttendee
  [__attendeesDataType:保护] =>
  串(5)阵
  [与会者] =>
  空值
  [attendeesOmitted] =>
  空值
  [colorId] =>
  空值
  [创造] =>
  串(24)2014-03-28T18:14:59.000Z
  [__creatorType:保护] =>
  串(19)Google_EventCreator
  [__creatorDataType:保护] =>
  串(0)
  [创造者] =>
  对象(Google_EventCreator)#21(4){
    [显示名] =>
    空值
    [电子邮件] =>
    串(75),%my_client_id_email%​​
    [ID] =>
    空值
    [自我] =>
    布尔(真)
  }
  [说明] =>
  空值
  [__endType:保护] =>
  串(20)Google_EventDateTime
  [__endDataType:保护] =>
  串(0)
  [结束] =>
  对象(Google_EventDateTime)#24(3){
    [日] =>
    空值
    [日期时间] =>
    串(20)2014-03-28T15:30:00Z
    [ - 时区] =>
    空值
  }
  [endTimeUnspecified] =>
  空值
  [ETAG] =​​>
  串(52),2DaeHpkENZGECFHdcr5l8tYxjD4 / MTM5NjAzMDQ5OTI1MTAwMA
  [__extendedPropertiesType:保护] =>
  串(30)Google_EventExtendedProperties
  [__extendedPropertiesDataType:保护] =>
  串(0)
  [extendedProperties] =>
  空值
  [__gadgetType:保护] =>
  串(18)Google_EventGadget
  [__gadgetDataType:保护] =>
  串(0)
  [小工具] =>
  空值
  [guestsCanInviteOthers] =>
  空值
  [guestsCanModify] =>
  空值
  [guestsCanSeeOtherGuests] =>
  空值
  [HANGOUTLINK] =>
  空值
  [htmlLink] =>
  串(178) \"https://www.google.com/calendar/event?eid=ZXNrYjdzNHBvZzlidnVhYjdqbmY2bWI3aWMgNjI1NDE0OTkwNTU3LW10cmpwaDZzNzRyNTVrbmFpc2p0OHVhY3ZqY3IxYzRxQGRldmVsb3Blci5nc2VydmljZWFjY291bnQuY29t\"
  [iCalUID] =>
  串(37)eskb7s4pog9bvuab7jnf6mb7ic@google.com
  [ID] =>
  串(26)eskb7s4pog9bvuab7jnf6mb7ic
  [厚道] =>
  串(14)历#事件
  [所在地] =>
  字符串(7)测试
  [锁定] =>
  空值
  [__organizerType:保护] =>
  串(21)Google_EventOrganizer
  [__organizerDataType:保护] =>
  串(0)
  [组织者] =>
  对象(Google_EventOrganizer)第22(4){
    [显示名] =>
    空值
    [电子邮件] =>
    串(75),%my_client_id_email%​​
    [ID] =>
    空值
    [自我] =>
    布尔(真)
  }
  [__originalStartTimeType:保护] =>
  串(20)Google_EventDateTime
  [__originalStartTimeDataType:保护] =>
  串(0)
  [originalStartTime] =>
  空值
  [privateCopy] =>
  空值
  [复发] =>
  空值
  [recurringEventId] =>
  空值
  [__remindersType:保护] =>
  串(21)Google_EventReminders
  [__remindersDataType:保护] =>
  串(0)
  [提醒] =>
  对象(Google_EventReminders)#25(4){
    [__overridesType:保护] =>
    串(20)Google_EventReminder
    [__overridesDataType:保护] =>
    串(5)阵
    [覆盖] =>
    空值
    [useDefault] =>
    布尔(真)
  }
  [序列] =>
  INT(0)
  [__sourceType:保护] =>
  串(18)Google_EventSource
  [__sourceDataType:保护] =>
  串(0)
  [源] =>
  空值
  [__startType:保护] =>
  串(20)Google_EventDateTime
  [__startDataType:保护] =>
  串(0)
  [开始] =>
  对象(Google_EventDateTime)第23(3){
    [日] =>
    空值
    [日期时间] =>
    串(20)2014-03-28T15:00:00Z
    [ - 时区] =>
    空值
  }
  [状态] =>
  字符串(9)证实
  [摘要]​​ =>
  串(16)测试约会
  [透明度] =>
  空值
  [更新] =>
  串(24)2014-03-28T18:14:59.251Z
  [知名度] =>
  字符串(6)公开
}


解决方案

它创造的服务帐户拥有,如果你想管理它,你必须与自己共享的日历的日历事件(!):

  $ =范围新Google_AclRuleScope();
$ scope->的setType(用户);
$ scope->的setValue('你的电子邮件-HERE');$规则=新Google_AclRule();
$基于规则>角色setRole('老板');
$基于规则> setScope($范围内);$结果= $服务 - >&ACL的GT;插入('主',$规则);

参考:<一href=\"http://stackoverflow.com/questions/21094240/who-owns-calendars-created-by-service-account-via-google-calendar-api-and-how-ca\">Who拥有通过谷歌日历API由服务帐户创建日历和如何对它们进行共享?

PS:还有PHP客户端库的新版本

So after digging around for several hours, I'm at a loss for a solution. I'm attempting to create an event on my primary calendar using v3 of Google's Calendar API, but I'm not experiencing the expected behavior.

I'm using server-to-server authentication in this instance. To do that I created service account credentials, moved my key pair to the same directory as my test script, and set Google Calendar API to "On" within the developer console.

Below you'll find the code at issue.

The expected result (as mentioned by Google) is that upon an event being successfully created/added to a calendar, an Event object or array (to your desire) will be returned. In either case I receive the Event object or array, but the event doesn't show up in the calendar. If I try to visit the "htmlLink" that's supplied with the created event data set, I receive an error message that says "This event does not exist."

I'd imagine that since I'm getting an Event object back with all necessary details, that it was successful; but no cigar. I tried playing around with the "visibility" property of the event (setting it to 'public'), but still no luck.

I'd really appreciate if someone can lend me a hand here.

[Code]

require_once __DIR__ . '/GoogleAPI/Google_Client.php';
require_once __DIR__ . '/GoogleAPI/contrib/Google_CalendarService.php';

$google = new Google_Client();

$google->setUseObjects(TRUE);
$google->setClientId(%my_client_id%);
$google->setAssertionCredentials(
    new Google_AssertionCredentials(
        %my_client_id_email%,
        array(
            'https://www.googleapis.com/auth/calendar',
            'https://www.googleapis.com/auth/calendar.readonly'
        ),
        file_get_contents(__DIR__ . '/google_key.p12')
    )
);

$service = new Google_CalendarService($google);

$event = new Google_Event();

$event->setSummary('Test Appointment');
$event->setLocation('Testing');
$event->setVisibility('public');

$start = new Google_EventDateTime();
$start->setDateTime('2014-03-28T10:00:00.000-05:00');
$event->setStart($start);

$end = new Google_EventDateTime();
$end->setDateTime('2014-03-28T10:30:00.000-05:00');
$event->setEnd($end);

$createdEvent = $service->events->insert('primary', $event, array('maxAttendees' => 1, 'sendNotifications' => FALSE));

var_dump($createdEvent);

=============================================================================

[Result]

object(Google_Event)#20 (56) {
  ["anyoneCanAddSelf"]=>
  NULL
  ["__attendeesType":protected]=>
  string(20) "Google_EventAttendee"
  ["__attendeesDataType":protected]=>
  string(5) "array"
  ["attendees"]=>
  NULL
  ["attendeesOmitted"]=>
  NULL
  ["colorId"]=>
  NULL
  ["created"]=>
  string(24) "2014-03-28T18:14:59.000Z"
  ["__creatorType":protected]=>
  string(19) "Google_EventCreator"
  ["__creatorDataType":protected]=>
  string(0) ""
  ["creator"]=>
  object(Google_EventCreator)#21 (4) {
    ["displayName"]=>
    NULL
    ["email"]=>
    string(75) "%my_client_id_email%"
    ["id"]=>
    NULL
    ["self"]=>
    bool(true)
  }
  ["description"]=>
  NULL
  ["__endType":protected]=>
  string(20) "Google_EventDateTime"
  ["__endDataType":protected]=>
  string(0) ""
  ["end"]=>
  object(Google_EventDateTime)#24 (3) {
    ["date"]=>
    NULL
    ["dateTime"]=>
    string(20) "2014-03-28T15:30:00Z"
    ["timeZone"]=>
    NULL
  }
  ["endTimeUnspecified"]=>
  NULL
  ["etag"]=>
  string(52) ""2DaeHpkENZGECFHdcr5l8tYxjD4/MTM5NjAzMDQ5OTI1MTAwMA""
  ["__extendedPropertiesType":protected]=>
  string(30) "Google_EventExtendedProperties"
  ["__extendedPropertiesDataType":protected]=>
  string(0) ""
  ["extendedProperties"]=>
  NULL
  ["__gadgetType":protected]=>
  string(18) "Google_EventGadget"
  ["__gadgetDataType":protected]=>
  string(0) ""
  ["gadget"]=>
  NULL
  ["guestsCanInviteOthers"]=>
  NULL
  ["guestsCanModify"]=>
  NULL
  ["guestsCanSeeOtherGuests"]=>
  NULL
  ["hangoutLink"]=>
  NULL
  ["htmlLink"]=>
  string(178) "https://www.google.com/calendar/event?eid=ZXNrYjdzNHBvZzlidnVhYjdqbmY2bWI3aWMgNjI1NDE0OTkwNTU3LW10cmpwaDZzNzRyNTVrbmFpc2p0OHVhY3ZqY3IxYzRxQGRldmVsb3Blci5nc2VydmljZWFjY291bnQuY29t"
  ["iCalUID"]=>
  string(37) "eskb7s4pog9bvuab7jnf6mb7ic@google.com"
  ["id"]=>
  string(26) "eskb7s4pog9bvuab7jnf6mb7ic"
  ["kind"]=>
  string(14) "calendar#event"
  ["location"]=>
  string(7) "Testing"
  ["locked"]=>
  NULL
  ["__organizerType":protected]=>
  string(21) "Google_EventOrganizer"
  ["__organizerDataType":protected]=>
  string(0) ""
  ["organizer"]=>
  object(Google_EventOrganizer)#22 (4) {
    ["displayName"]=>
    NULL
    ["email"]=>
    string(75) "%my_client_id_email%"
    ["id"]=>
    NULL
    ["self"]=>
    bool(true)
  }
  ["__originalStartTimeType":protected]=>
  string(20) "Google_EventDateTime"
  ["__originalStartTimeDataType":protected]=>
  string(0) ""
  ["originalStartTime"]=>
  NULL
  ["privateCopy"]=>
  NULL
  ["recurrence"]=>
  NULL
  ["recurringEventId"]=>
  NULL
  ["__remindersType":protected]=>
  string(21) "Google_EventReminders"
  ["__remindersDataType":protected]=>
  string(0) ""
  ["reminders"]=>
  object(Google_EventReminders)#25 (4) {
    ["__overridesType":protected]=>
    string(20) "Google_EventReminder"
    ["__overridesDataType":protected]=>
    string(5) "array"
    ["overrides"]=>
    NULL
    ["useDefault"]=>
    bool(true)
  }
  ["sequence"]=>
  int(0)
  ["__sourceType":protected]=>
  string(18) "Google_EventSource"
  ["__sourceDataType":protected]=>
  string(0) ""
  ["source"]=>
  NULL
  ["__startType":protected]=>
  string(20) "Google_EventDateTime"
  ["__startDataType":protected]=>
  string(0) ""
  ["start"]=>
  object(Google_EventDateTime)#23 (3) {
    ["date"]=>
    NULL
    ["dateTime"]=>
    string(20) "2014-03-28T15:00:00Z"
    ["timeZone"]=>
    NULL
  }
  ["status"]=>
  string(9) "confirmed"
  ["summary"]=>
  string(16) "Test Appointment"
  ["transparency"]=>
  NULL
  ["updated"]=>
  string(24) "2014-03-28T18:14:59.251Z"
  ["visibility"]=>
  string(6) "public"
}

解决方案

It's creating the event in the calendar owned by the service account, if you want to manage it, you have to share the calendar with yourself (!):

$scope = new Google_AclRuleScope();
$scope->setType('user');
$scope->setValue('YOUR-EMAIL-HERE');

$rule = new Google_AclRule();
$rule->setRole('owner');
$rule->setScope($scope);

$result = $service->acl->insert('primary', $rule);

Reference: Who owns calendars created by service account via Google Calendar API and how can they be shared?

PS: there's a new version of the PHP client library.

这篇关于谷歌日历API第3版 - 不创建事件(服务器到服务器身份验证)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆