Php 从命令行访问google日历
我已经激活了GoogleAPI控制台,并创建了一个项目,包括OAuth凭据。我选择了“桌面应用程序”设置,因为此应用程序将在浏览器之外运行,从CLI运行(实际上仅在我的计算机上运行) 我还下载了客户端库,如下所述: 我编辑了Php 从命令行访问google日历,php,oauth-2.0,google-calendar-api,Php,Oauth 2.0,Google Calendar Api,我已经激活了GoogleAPI控制台,并创建了一个项目,包括OAuth凭据。我选择了“桌面应用程序”设置,因为此应用程序将在浏览器之外运行,从CLI运行(实际上仅在我的计算机上运行) 我还下载了客户端库,如下所述: 我编辑了google-api-php-client/src/config.php编辑密钥application\u-name,oauth2\u-client\u-id,oauth2\u-client\u-secret,oauth2\u-redirect\u-uri和developer
google-api-php-client/src/config.php
编辑密钥application\u-name
,oauth2\u-client\u-id
,oauth2\u-client\u-secret
,oauth2\u-redirect\u-uri
和developer\u-key
等等
我还删除了服务
中的所有其他服务
现在,我有了以下应用程序,它们来自指南中的示例:
<?php
require_once 'google-api-php-client/src/apiClient.php';
require_once "google-api-php-client/src/contrib/apiCalendarService.php";
session_start();
$apiClient = new apiClient();
$apiClient->setUseObjects(true);
$service = new apiCalendarService($apiClient);
if (isset($_SESSION['oauth_access_token'])) {
$apiClient->setAccessToken($_SESSION['oauth_access_token']);
} else {
$token = $apiClient->authenticate();
$_SESSION['oauth_access_token'] = $token;
}
$event = new Event();
$event->setSummary('Appointment');
$event->setLocation('Somewhere');
$start = new EventDateTime();
$start->setDateTime('2011-06-03T10:00:00.000-07:00');
$start->setTimeZone('America/Los_Angeles');
$event->setStart($start);
$end = new EventDateTime();
$end->setDateTime('2011-06-03T10:25:00.000-07:00');
$end->setTimeZone('America/Los_Angeles');
$event->setEnd($end);
$event->setRecurrence(array('RRULE:FREQ=WEEKLY;UNTIL=20110701T100000-07:00'));
$attendee1 = new EventAttendee();
$attendee1->setEmail('attendeeEmail');
// ...
$attendees = array($attendee1,
// ...
);
$event->attendees = $attendees;
$recurringEvent = $service->events->insert('primary', $event);
echo $recurringEvent->getId();
我认为这可能是由几种原因造成的。我的2美分:
你们有几本注册的日历吗?可能您想要插入事件的日历不是“主”(=默认值?)日历(或者您的Oauth cred数据指的是不同的日历)。
如果是,则更换此线路
$service->events->insert('primary', $event);
与
日历id有点难找到…请查找它。例如,您可以在您的google帐户主页/日历/齿轮符号/设置/单击底部的日历名称/日历详细信息设置页面上找到它
我的重定向url(对于web应用程序)指向发出oauth请求的.php页面。如果我定义了另一个重定向,这次是我自己的。令人困惑是的,但它对我有用
$service->events->insert('primary', $event);
$calendar_id = "somelongstring@group.calendar.google.com"; //look this up from calendar /settings calendar details settings page at the bottom
$service->events->insert($calendar_id, $event);