我想从服务帐户在Google日历中创建新活动。 我可以正确访问并打印列出我所有的日历。 但是当我想创建一个新事件时,响应是403 Forbidden。从Google服务帐户编辑Google日历活动:403
我的代码:
require_once 'src/Google_Client.php';
require_once 'src/contrib/Google_CalendarService.php';
session_start();
const CLIENT_ID = 'XXXXXXXXXX.apps.googleusercontent.com';
const SERVICE_ACCOUNT_NAME = '[email protected]';
const KEY_FILE = 'google_src/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-privatekey.p12';
$client = new Google_Client();
$client->setApplicationName("APP_NAME");
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
$key = file_get_contents(KEY_FILE);
$client->setClientId(CLIENT_ID);
$client->setAssertionCredentials(new Google_AssertionCredentials(
SERVICE_ACCOUNT_NAME,
'https://www.google.com/calendar/feeds/MY_CALENDAR_ID/private/full/',
$key)
);
$client->setClientId(CLIENT_ID);
$cal = new Google_CalendarService($client);
$event = new Google_Event();
$event->setSummary('Bon dia pel matí!');
$event->setLocation('Somewhere');
$start = new Google_EventDateTime();
$start->setDateTime('2012-08-06T10:00:00.000-07:00');
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime('2012-09-06T10:25:00.000-07:00');
$event->setEnd($end);
$createdEvent = $cal->events->insert(CALENDAR_NAME, $event);
和服务器响应:
(403) Forbidden
任何想法?也许其他范围,或允许编辑事件(我不知道我可以配置这个,我已经搜索它,承诺)
当然,我的日历是公共日历。
任何帮助将受到欢迎:)
谢谢!
也许它是被禁止的原因是什么? – Peon 2012-08-08 11:04:06
也许,但我不知道是否有某个地方我可以编辑活动。在日历配置中,我没有看到任何内容,并且我激活了日历API。我没有问题列出caendars和事件。只能编辑和创建。但是,真的,我花了很多时间来搜索这个选项,并且没有什么可以做的:S 谢谢 – eMarine 2012-08-08 11:06:23