谷歌日历API创建事件返回403禁止和日历是公共-PHP


Google Calendar API create event return 403 Forbidden and calendar is public - PHP

我正试图使用Google Calendar Api 3添加一个事件并通过电子邮件发送,但Google Api返回403 Forbidden,并且我的日历设置为公用。我的代码是:

ini_set('display_errors', 1);
require 'Google/Client.php';
require 'Google/Service/Calendar.php';
session_start();
const CLIENT_ID = '**************.apps.googleusercontent.com';
const SERVICE_ACCOUNT_NAME = '**************@developer.gserviceaccount.com';
const KEY_FILE = '**************-privatekey.p12';
$client = new Google_Client();
$client->setApplicationName("Calendar App");
//$client->setUseObjects(true); //IF USING SERVICE ACCOUNT (YES)
if (isset($_SESSION['token'])) {
    $client->setAccessToken($_SESSION['token']);
}
$key = file_get_contents(KEY_FILE);
$client->setClientId(CLIENT_ID);
$client->setAssertionCredentials(new Google_Auth_AssertionCredentials(
SERVICE_ACCOUNT_NAME, 'https://www.google.com/calendar/feeds/**************@group.calendar.google.com/private/full/',
$key)
);
$client->setClientId(CLIENT_ID);
$cal = new Google_Service_Calendar($client);
$event = new Google_Service_Calendar_Event();
$event->setSummary('App Sum');
$event->setLocation('App Location');
$start = new Google_Service_Calendar_EventDateTime();
$start->setDateTime('2014-05-19T10:30:00.000-05:00');
$event->setStart($start);
$end = new Google_Service_Calendar_EventDateTime();
$end->setDateTime('2014-05-20T11:30:00.000-05:00');
$event->setEnd($end);
$attendeel = new Google_Service_Calendar_EventAttendee();
$attendeel->setEmail('**************@gmail.com');
$attendees = array($attendeel);
$event->attendees = $attendees;
$cal->events->insert('**************@group.calendar.google.com', $event);

从中获取代码http://amazewebs.yitweb.com/#scriptv4,有一个类似的代码从谷歌服务帐户编辑谷歌日历事件:403开发者说如果没有日历设置,这不是代码

他们知道是否有其他配置,或者代码是否真的是问题所在吗?

如果您有权访问域管理员帐户,您可以将日历更新作为该帐户发布,而无需以管理员身份登录。你可以通过填写$client:的所有参数来做到这一点

setAssertionCredentials(new Google_Auth_AssertionCredentials(
     SERVICE_ACCOUNT_NAME,           
     'https://www.google.com/calendar/feeds/**************@group.calendar.google.com/private/full/',
     $key,
     'notasecret',
     'http://oauth.net/grant_type/jwt/1.0/bearer',
     'your admin account email');

我也玩过这种东西。我让列表事件起作用,但后来改为添加事件,我得到了401。我发现您必须通过**************@developer.gserviceaccount.com电子邮件与共享日历。您可以转到日历>我的日历>(名称)>共享此日历,然后在与特定人员共享下,添加该gserviceaccount电子邮件并设置相应的权限。

非常感谢这篇文章和这篇文章。