doulun1939 2017-06-03 17:44
浏览 76
已采纳

Google Calendar API - 禁止访问 - 服务帐户出错

I try to use the Google Calendar API by php running server side.

I created a service account and use its credentials (via the json file). I am NOT using G Suite.

Now I am able to list events of my calendar but I get a Forbidden - Error, when I try to create a new event.

I shared my calendar with the service account's email address and gave it admin rights for the calendar. I don't know what I am doing wrong! I just can't get it working. I am also using the scope Google_Service_Calendar::CALENDAR.

The exception: 403 - Forbidden

I have no idea how to debug this problem and how to proceed further.

Can you help me?

Edit: here is my calling code:

putenv('GOOGLE_APPLICATION_CREDENTIALS=../google-service-account.json');

$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->setScopes([Google_Service_Calendar::CALENDAR]);
$client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
$service = new Google_Service_Calendar($client);

$event = new Google_Service_Calendar_Event([
  'summary' => $name,
  'location' => $location,
  'description' => $desc,
  'start' => [
    'dateTime' => $start,
    'timeZone' => $timezone,
  ],
  'endTimeUnspecified' => true,
]);

$calendar = $service->calendars->get($calendarId);
$settings = $service->settings->listSettings();
$list = $service->acl->listAcl($calendarId);
$event = $service->events->insert($calendarId, $event);

The first three service calls ($calender = ..., $settings = ... and $list = ...) work fine and in the acl I can also see that the email address of my service account has all rights (role: owner). But the last line $event = ... gives the forbidden error...

  • 写回答

1条回答 默认 最新

  • doujizhong8352 2017-06-13 21:19
    关注
    'endTimeUnspecified' => true,
    

    is causing your problem (its googles fault, but you cant tell them that)

    if you change to

     'end' => [
    'dateTime' => $start2,
    'timeZone' => $timezone,
     ],
    

    it will work (i know it is not what you want and maybe you can figure out a way to adjust $start2 to give you what you want as an end time but the endTimeUnspecified is what is causing it to say 403 forbidden

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 通过下面文章的方法求手机号段
  • ¥15 有偿求码,CNN+LSTM实现单通道脑电信号EEG的睡眠分期评估
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体