简体   繁体   English

使用API​​从Google日历检索事件

[英]Retrieve Events from Google Calendar Using API

I am a complete newbie with Google Calendar API and PHP, I can't seem to figure out on how to implement the thing that I would like to do. 我是使用Google Calendar API和PHP的完全新手,我似乎无法弄清楚如何实现我想做的事情。 Basically, I want to retrieve the events from a google calendar with calendarID of webapps098@gmail.com. 基本上,我想从带有Google日历的webapps098@gmail.com的Google日历中检索事件。 My current code goes something like 我当前的代码是这样的

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;
    }

I am receiving the error : 我收到错误:

exception 'Google_ServiceException' with message 'Error calling GET https://www.googleapis.com/calendar/v3/calendars/webapps098@gmail.com : (401) Login Required' in C:\\xampp\\htdocs\\Test\\google-api-php-client\\src\\io\\Google_REST.php:66 Stack trace: #0 C:\\xampp\\htdocs\\Test\\google-api-php-client\\src\\io\\Google_REST.php(36): Google_REST::decodeHttpResponse(Object(Google_HttpRequest)) #1 C:\\xampp\\htdocs\\Test\\google-api-php-client\\src\\service\\Google_ServiceResource.php(186): Google_REST::execute(Object(Google_HttpRequest)) #2 C:\\xampp\\htdocs\\Test\\google-api-php-client\\src\\contrib\\Google_CalendarService.php(300): Google_ServiceResource->__call('get', Array) #3 C:\\xampp\\htdocs\\Test\\refreshscript.php(10): Google_CalendarsServiceResource->get('webapps098@gmai...') #4 {main} 异常“ Google_ServiceException”,消息为“在C:\\ xampp \\ htdocs \\ Test \\ google-中调用GET https://www.googleapis.com/calendar/v3/calendars/webapps098@gmail.com错误:(401)需要登录” api-php-client \\ src \\ io \\ Google_REST.php:66堆栈跟踪:#0 C:\\ xampp \\ htdocs \\ Test \\ google-api-php-client \\ src \\ io \\ Google_REST.php(36):Google_REST: :decodeHttpResponse(Object(Google_HttpRequest))#1 C:\\ xampp \\ htdocs \\ Test \\ google-api-php-client \\ src \\ service \\ Google_ServiceResource.php(186):Google_REST :: execute(Object(Google_HttpRequest))#2 C:\\ xampp \\ htdocs \\ Test \\ google-api-php-client \\ src \\ contrib \\ Google_CalendarService.php(300):Google_ServiceResource-> __ call('get',Array)#3 C:\\ xampp \\ htdocs \\ Test \\ refreshscript.php(10):Google_CalendarsServiceResource-> get('webapps098 @ gmai ...')#4 {main}

I wish anyone can help! 希望任何人都能帮忙! Sorry and thank you for your understanding. 抱歉,谢谢您的理解。

You are trying to get something which needs to have an oAuth token. 您正在尝试获取需要具有oAuth令牌的内容。 If you are just pulling events from public calendar, I recommend you to go for Google feeds instead for Google APIs. 如果您只是从公共日历中提取事件,建议您使用Google供稿,而不要使用Google API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM