我想從服務帳戶在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