【问题标题】:Google Calendar APIv3 mess谷歌日历 APIv3 乱七八糟
【发布时间】:2016-05-16 02:59:24
【问题描述】:

我尝试将事件添加到日历中。我已经在 google 控制台中创建了一个适当的应用程序,获得了 ID、Secret 等。我什至获得了已创建事件的 ID,但此事件在日历仪表板中不可见。

session_start();
require_once dirname(__FILE__).'google-api-php-client/src/Google_Client.php';
require_once dirname(__FILE__).'google-api-php-client/src/contrib/Google_CalendarService.php';

ini_set('display_errors', 1);

define('CLIENT_ID','XXX');
define('SERVICE_ACCOUNT_NAME','XXX');
define('KEY_FILE',dirname(__FILE__).'API Project-XXX.p12');

$client = new Google_Client();
$client->setApplicationName("Kalendarz");
$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_AssertionCredentials(SERVICE_ACCOUNT_NAME,array('https://www.googleapis.com/auth/calendar'),$key));

$client->setClientId(CLIENT_ID);
$cal = new Google_CalendarService($client);


$calList = $cal->calendarList->listCalendarList();
print "<h1>Calendar List</h1><pre>" . print_r($calList, true) . "</pre>";


if (isset($_GET['logout']))
{
   unset($_SESSION['token']);
}

if (isset($_GET['code']))
{
   $client->authenticate($_GET['code']);
   $_SESSION['token'] = $client->getAccessToken();
   header('Location: http://' . $_SERVER['HTTP_HOST'] .
$_SERVER['PHP_SELF']);
}

if (isset($_SESSION['token']))
{
   $client->setAccessToken($_SESSION['token']);
}


// Creates a test event
$event = new Google_Event();
$event->setSummary('Appointment2');
$event->setLocation('Somewhere2');
$start = new Google_EventDateTime();
$start->setDateTime('2014-10-11T10:00:00.000-01:00');
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime('2014-10-11T10:25:00.000-01:00');
$event->setEnd($end);
$attendee1 = new Google_EventAttendee();
//$attendee1->setEmail('XXX');
//$attendees = array($attendee1);
//$event->attendees = $attendee1;
//echo "<pre>";
//var_dump($cal);
$createdEvent = $cal->events->insert('primary', $event);

echo $createdEvent->getId();

/*
$event = new Google_Event();
$event = $service->events->get("XXX", $evID);
echo $event->getSummary();
*/

结果是:

Google_CalendarList Object
(
    [etag] => "1412846388446000"
    [__itemsType:protected] => Google_CalendarListEntry
    [__itemsDataType:protected] => array
    [items] => Array
        (
        )

    [kind] => calendar#calendarList
    [nextPageToken] => 
    [nextSyncToken] => 00001412846388446000
)
arkd3j1j8ilgi71p6pdp242gp0

【问题讨论】:

    标签: google-calendar-api


    【解决方案1】:

    我认为您的活动已成功创建,其活动 ID 为 arkd3j1j8ilgi71p6pdp242gp0 ;)

    【讨论】:

      猜你喜欢
      • 2014-10-12
      • 1970-01-01
      • 1970-01-01
      • 2019-08-16
      • 1970-01-01
      • 1970-01-01
      • 2014-11-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多