Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从google日历返回json并用php解析_Php_Json - Fatal编程技术网

从google日历返回json并用php解析

从google日历返回json并用php解析,php,json,Php,Json,我应该将alt=json和日期变量放在url中的什么位置。当我从url中排除日期时,它可以正常工作,但对它们无效。另外,当我试图打印一个特定的对象时,我会得到一个错误,即该对象不存在。谢谢大家! 试试看- $current = $_GET['current']; $future = $_GET['future']; //$CMD = $_GET['CMD']; $current = mktime(0,0,0,date("m"),date("d"),date("Y")); $currentDat

我应该将alt=json和日期变量放在url中的什么位置。当我从url中排除日期时,它可以正常工作,但对它们无效。另外,当我试图打印一个特定的对象时,我会得到一个错误,即该对象不存在。谢谢大家!

试试看-

$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];

似乎URL方案要求基本视图,然后添加完整视图。你只能有一个

尝试以下任一方法:

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


我第一次尝试了这个,但打开流失败了:HTTP请求失败!HTTP/1.0 400错误请求
$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";