在 PHP 应用程序中集成 Google Calendar(7)
 
- UID
- 1066743
|

在 PHP 应用程序中集成 Google Calendar(7)
搜索事件和所有的 Google Data 提要一样,Calendar API 也允许开发人员通过在 REST 请求中添加以下参数来改变输出:
- start-index 参数,指定条目的起始偏移量
- max-results 参数,指定检索的条目数
- start-min 和 start-max 参数,指定返回条目的日期范围
- orderby 参数,指定如何对条目排序
示范了其中的一些参数,将 的输出限制为今后七天内的条目,并按开始日期排列:
清单 11. 按日期搜索事件1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
| <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Listing calendar contents</title>
<style>
body {
font-family: Verdana;
}
li {
border-bottom: solid black 1px;
margin: 10px;
padding: 2px;
width: auto;
padding-bottom: 20px;
}
h2 {
color: red;
text-decoration: none;
}
span.attr {
font-weight: bolder;
}
</style>
</head>
<body>
<?php
// set configuration parameters
$userid = 'username%40googlemail.com';
$magicCookie = 'cookie';
$start = urlencode(date(DATE_ATOM, strtotime('today 00:00')));
$end = urlencode(date(DATE_ATOM, strtotime('+7 days 23:59')));
// build feed URL
$feedURL = "http://www.google.com/calendar/feeds/$userid/private-
$magicCookie/basic?start-min=$start&start-max=$end&orderby=starttime";
// read feed into SimpleXML object
$sxml = simplexml_load_file($feedURL);
// get number of events
$counts = $sxml->children('http://a9.com/-/spec/opensearchrss/1.0/');
$total = $counts->totalResults;
?>
<h1><?php echo $sxml->title; ?></h1>
<?php echo $total; ?> event(s) found.
<p/>
<ol>
<?php
// iterate over entries in category
// print each entry's details
foreach ($sxml->entry as $entry) {
$title = stripslashes($entry->title);
$summary = stripslashes($entry->summary);
echo "<li>\n";
echo "<h2>$title</h2>\n";
echo "$summary <br/>\n";
echo "</li>\n";
}
?>
</ol>
</body>
</html>
|
也可以对日程表条目进行全文本搜索查询,只返回和特定词语匹配的条目。 提供了一个例子:
清单 12. 按查询关键字搜索1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
| <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Listing calendar contents</title>
<style>
body {
font-family: Verdana;
}
li {
border-bottom: solid black 1px;
margin: 10px;
padding: 2px;
width: auto;
padding-bottom: 20px;
}
h2 {
color: red;
text-decoration: none;
}
span.attr {
font-weight: bolder;
}
</style>
</head>
<body>
<?php
// set configuration parameters
$userid = 'username%40googlemail.com';
$magicCookie = 'cookie';
$query = urlencode('party');
// build feed URL
$feedURL = "http://www.google.com/calendar/feeds/$userid/private-
$magicCookie/basic?q=$query";
// read feed into SimpleXML object
$sxml = simplexml_load_file($feedURL);
// get number of events
$counts = $sxml->children('http://a9.com/-/spec/opensearchrss/1.0/');
$total = $counts->totalResults;
?>
<h1><?php echo $sxml->title; ?></h1>
<?php echo $total; ?> event(s) found.
<p/>
<ol>
<?php
// iterate over entries in category
// print each entry's details
foreach ($sxml->entry as $entry) {
$title = stripslashes($entry->title);
$summary = stripslashes($entry->summary);
echo "<li>\n";
echo "<h2>$title</h2>\n";
echo "$summary <br/>\n";
echo "</li>\n";
}
?>
</ol>
</body>
</html>
|
|
|
|
|
|
|