使用API从Google日历检索事件


Retrieve Events from Google Calendar Using API

我是一个完整的新手与谷歌日历API和PHP,我似乎不能弄清楚如何实现的事情,我想做的。基本上,我想从一个calendarID为webapps098@gmail.com的google日历中检索事件。我当前的代码类似于

require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_BooksService.php';
require_once 'google-api-php-client/src/contrib/Google_CalendarService.php';
$client = new Google_Client();
$client->setUseObjects(true);
$service = new Google_CalendarService($client);
try{
    $events = $service->calendars->get('webapps098@gmail.com');
    print_r($events);
}catch(Exception $e){
    echo $e;
    }

我收到错误:

异常'Google_ServiceException'与消息'错误调用GEThttps://www.googleapis.com/calendar/v3/calendars/webapps098@gmail.com:(401)需要登录C: ' xampp '根测试' ' google-api-php-client ' src ' io ' Google_REST.php: 66堆栈跟踪:#0C: ' xampp '根测试' ' google-api-php-client ' src ' io ' Google_REST.php (36):Google_REST:: decodeHttpResponse(对象(Google_HttpRequest) # 1C: ' xampp '根'测试' google-api-php-client ' src '服务' Google_ServiceResource.php (186):Google_REST:执行(对象(Google_HttpRequest)) # 2C: ' xampp '根测试' ' google-api-php-client ' src ' contrib ' Google_CalendarService.php (300):Google_ServiceResource->__call('get', Array) #3C: ' xampp '根' Test ' refreshscript.php (10):Google_CalendarsServiceResource->get('webapps098@gmai...') #4 {main}

我希望任何人都能帮忙!对不起,谢谢您的理解。

您正在尝试获得需要具有oAuth令牌的东西。如果您只是从公共日历中提取事件,我建议您使用Google feed而不是Google api。