从谷歌日历返回json并使用php解析

时间:2012-04-30 19:57:15

标签: php json

$current = $_GET['current'];
$future = $_GET['future'];
//$CMD = $_GET['CMD'];

$current = mktime(0,0,0,date("m"),date("d"),date("Y"));
$currentDate = date("Y-m-d",$current);

$future = mktime(0,0,0,date("m"),date("d")+7,date("Y"));
$futureDate = date("Y-m-d", $future);
//need to get the futureDate for URL
//$futrureDate = date("Y-m-d",$_GET['finalDate'])

// build feed URL
$googleURL = "http://www.google.com/calendar/feeds/$userid/private-$magicWord/basic?start-min=$currentDate&start-max=$futureDate/full?alt=json";
//$googleURL = "http://www.google.com/calendar/feeds/$userid/private-$magicWord/basic?alt=json";
//$url = "http://www.google.com/calendar/feeds/developer-calendar@google.com/public/full?alt=json";
$data = file_get_contents($googleURL);
echo $data;
//$json = json_encode($data);
//echo $json;
//By default json_decode returns an stdClass object. You have to give a second parameter for this function TRUE.
$object = json_decode($json,TRUE);
print_r($object->title[1]);

//echo $object->title[0];

我在哪里将alt = json放在带有日期变量的url中。当我从网址中排除日期但随后将其无效时,它可以正常工作。当我尝试打印特定对象时,我得到一个错误,该对象不存在。谢谢!

2 个答案:

答案 0 :(得分:0)

尝试 -

$googleURL = "http://www.google.com/calendar/feeds/$userid/private-$magicWord/basic?start-min=$currentDate&start-max=$futureDate/full&alt=json";

答案 1 :(得分:0)

看起来URL方案要求基本视图然后添加完整视图。 (你只能有一个。)

尝试:

$googleURL = "http://www.google.com/calendar/feeds/$userid/private-$magicWord/basic?start-min=$currentDate&start-max=$futureDate&alt=json";

$googleURL = "http://www.google.com/calendar/feeds/$userid/private-$magicWord/full?start-min=$currentDate&start-max=$futureDate&alt=json";