终于找到了解决办法。在这里发帖,如果我得到任何空闲时间,可能会在以后完成一个完整的教程:)。希望它可以帮助别人。
https://console.developers.google.com/iam-admin/projects 创建这应该带你到控制台创建后一个项目......如果不是在这里是在图书馆部分启用“谷歌日历API”控制台链接https://console.developers.google.com/
。搜索Google Calendar API,选择它并使用顶部显示的启用按钮。
转到凭据部分并添加服务帐户密钥。新的服务帐户(任何你想要的名字)。
罗尔斯:
项目>浏览器
的App Engine> App Engine的浏览器
存储>对象查看器
你可能并不需要所有这些,但似乎是combonation是为我工作。确保选择了JSON,然后创建它将下载一个.json文件。它只下载一次,无法重新下载,因此请确保您下载并将其保存在安全的地方。
在此处下载PHP的最新API https://developers.google.com/google-apps/calendar/downloads并将其上传到您网站的任何位置。相当大的支持文件可能需要一段时间才能上传。
那么这是PHP代码为我工作:)
CALENDARID是你的日历... 从您的谷歌日历的ID,使用弹出,然后选择“日历设置”。然后在“日历地址:”部分的底部记下日历ID。应该是某种google.com电子邮件地址或您的电子邮件地址,如果您通过gSuite工具进行设置。
“YOURJSON.json”是您先前下载的json文件的名称。建议让它更安全的是将其上传到您网站的根目录并从那里链接到它。由于它只是读取角色,所以不应该引起任何问题,以免出现问题。
require_once行是您将google API上传到服务器的任何位置。不要忘记/vendor/autoload.php部分:)。
这是为我工作的解决方案(2017-04-24)。 PHP代码的最后一行是一个通用的echo命令,因此您可以看到您获得的数组以及所有可用的数据。我没有看到的唯一一件事就是事件的自定义颜色。有一个空间,但似乎并没有结束。
<?php
$maxEvents = 100;
$minStartDate = date('c');
$calendarId = 'CALENDARID';
//path to the google API on your server
require_once 'inc/google-api-php-client-2.1.3_PHP54/vendor/autoload.php';
//set environment variable to use your downloaded Service account key
putenv("GOOGLE_APPLICATION_CREDENTIALS=YOURJSON.json");
$scope = 'https://www.googleapis.com/auth/calendar.readonly';
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->setScopes($scope);
$service = new Google_Service_Calendar($client);
//options link
// https://developers.google.com/google-apps/calendar/v3/reference/events/list
$options = array(
'maxResults' => $maxEvents,
'orderBy' => 'startTime',
'singleEvents' => TRUE,
//UNIX timestamp format
'timeMin' => $minStartDate,
//to use a calendar other than the default uncomment and enter the calendar's ID
//not really needed here since you're using the $calendarId but does pull another calendar and more for completeness
//'iCalUID' => 'CAL_ID_FROM_GOOGLE_CALENDAR'
);
$results = $service->events->listEvents($calendarId, $options);
//echo 'results<br><pre>';print_r($results); echo '</pre><br>';
?>