Google Calendar Api在本周获得活动 [英] Google Calendar Api get events on current week

查看:134
本文介绍了Google Calendar Api在本周获得活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从Google公开的Google日历中使用Google API获取本周活动列表。



我的所有配置都很好,我可以做任何测试,在一个网页上列出并显示事件,但是我搜索了任何类型的查询,以获得本周使用服务器日期而不是成功的事件。



我认为可以使用中指定的q选项Google Api文档,但我不知道我能指出本周的人。



编辑:
我找到了一个解决方案并发布为答案。

解决方案

我在这里发布解决方案,我找到我的问题:
我计算了期望的范围日期与 strtotime ,在我的情况下,前一个星期日和下一个星期一之间的所有天。然后我将这些参数传递给我的请求:

$ p $ function getEvents($ service,$ calendarId){
// De un domingo al otro
$ date_inicio =日期('c',strtotime(上一个星期日));
$ date_fin = date('c',strtotime(next monday));
$ optParams = array(
'orderBy'=>'startTime',
'singleEvents'=> TRUE,
'timeMin'=> $ date_inicio,
'timeMax'=> $ date_fin
);
$ results = $ service-> events-> listEvents($ calendarId,$ optParams);

if(count($ results-> getItems())== 0){
printNingúnevento encontrado.\\\
;
} else {
foreach($ results-> getItems()as $ event){
$ start = $ event-> start-> dateTime;
if(empty($ start)){
$ start = $ event-> start-> date;
}
printf(%s(%s)\\\
,$ event-> getSummary(),$ start);
echo $ start。'< br>'。$ event-> getSummary()。'< br>'。
printf(%s(%s)\\\
< br>< br>,$ event-> getDescription(),$ start);
}
}
}


I'm trying to get a list of events on the current week from one public Google Calendar using the Google Api.

All my configurations are good, i can do any tests, list and show events in one web page, but i searched any sort of query for get the events of the current week using the server date with out success.

I think it's possible using the "q" option indicated in the Google Api documentation, but i don't know who i can indicate the current week.

EDIT: I found one solution and posted as answer.

解决方案

I'm posting here the solution i find for my question: I calculated the desired range of dates with strtotime, in my case, all days between previous sunday and next monday. Then i pass these parametres to my request:

function getEvents($service, $calendarId){
//De un Domingo al otro
$date_inicio = date('c',strtotime( "previous sunday" ));
$date_fin = date('c',strtotime( "next monday" ));
$optParams = array(
  'orderBy' => 'startTime',
  'singleEvents' => TRUE,
  'timeMin' => $date_inicio,
  'timeMax' => $date_fin
  );
  $results = $service->events->listEvents($calendarId, $optParams);

if (count($results->getItems()) == 0) {
    print "Ningún evento encontrado.\n";
} else {
    foreach ($results->getItems() as $event) {
        $start = $event->start->dateTime;
        if (empty($start)) {
            $start = $event->start->date;
        }
        printf("%s (%s)\n", $event->getSummary(), $start);
        echo $start.'<br>'.$event->getSummary().'<br>'.$event->getDescription().'<hr>';
        printf("%s (%s)\n<br><br>", $event->getDescription(), $start);
    }
}
}

这篇关于Google Calendar Api在本周获得活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆