Google API를 사용하여 Google 캘린더에서 JSON 데이터를 가져 오는 간단한 PHP 스크립트가 있습니다. 목표는 JSON을 거친 다음 각 이벤트에 대해 시작일과 요약 만 반환하는 것입니다. 내가 다시 받고 있어요 것은 다음과 같습니다 넌센스입니다Google 캘린더에서 반환 된 JSON에서 데이터를 변환 할 때 PHP에서 어디가 잘못 되었습니까?
$eventsCalendar = json_decode(file_get_contents("https://www.googleapis.com/calendar/v3/calendars/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxgroup.calendar.google.com/events?key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
//var_dump($eventsCalendar);
$outputJSON = array();
foreach ($eventsCalendar as $event)
{
array_push($outputJSON, array(
'title' => $event['summary'],
'start' => $event['start']['dateTime'],
));
}
header('Content-Type: application/json; charset=UTF-8');
echo json_encode($outputJSON);
:
array(8) { ["kind"]=> string(15) "calendar#events" ["etag"]=> string(57) ""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"" ["summary"]=> string(24) "xxxxxxxxxxxxxxxxxxxxxxxxx" ["description"]=> string(0) "" ["updated"]=> string(24) "2013-09-05T10:12:10.027Z" ["timeZone"]=> string(10) "xxxxx/xxxxx" ["accessRole"]=> string(6) "reader" ["items"]=> array(7) { [0]=> array(17) { ["kind"]=> string(14) "calendar#event" ["etag"]=> string(52) ""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"" ["id"]=> string(26) "xxxxxxxxxxxxxxxxxxxxx" ["status"]=> string(9) "confirmed" ["htmlLink"]=> string(138) "https://www.google.com/calendar/event?xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ["created"]=> string(24) "2013-08-27T00:44:24.000Z" ["updated"]=> string(24) "2013-08-29T05:33:04.171Z" ["summary"]=> string(18) "xxxxxxxxxxxxxxxxxxxxx" ["location"]=> string(27) "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ["creator"]=> array(2) { ["email"]=> string(34) "[email protected]" ["displayName"]=> string(20) "xxxxxxxxxxxxxxxxxxxxxxxxx" } ["organizer"]=> array(3) { ["email"]=> string(52) "[email protected]" ["displayName"]=> string(24) "xxxxxxxxxxxxxxxxxxxxxxxxxx" ["self"]=> bool(true) } ["start"]=> array(2) { ["dateTime"]=> string(25) "2013-09-06T20:00:00+09:00" ["timeZone"]=> string(10) "xxxxx/xxxxx" } ["end"]=> array(2) { ["dateTime"]=> string(25) "2013-09-03T21:00:00+09:00" ["timeZone"]=> string(10) "xxxxx/xxxxx" } ["recurrence"]=> array(1) { [0]=> string(28) "RRULE:FREQ=MONTHLY;BYDAY=1TU" } ["visibility"]=> string(6) "public" ["iCalUID"]=> string(37) "[email protected]" ["sequence"]=> int(1) } [1]=> array(16) { ["kind"]=> string(14) "calendar#event" ["etag"]=> string(52) ""xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"" ["id"]=> string(26) "xxxxxxxxxxxxxxxxxxxxxxxx" ["status"]=> string(9) "confirmed" ["htmlLink"]=> string(138) "https://www.google.com/calendar/event?eid=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ["created"]=> string(24) "2013-08-25T08:03:53.000Z" ["updated"]=> string(24) "2013-08-29T05:33:15.417Z" ["summary"]=> string(18) "xxxxxxxxxxxxxxxxxxxxxxxxxxx" ["location"]=> string(27) "xxxxxxxxxxxxxxxxxxxxxxxxxxx" ["creator"]=> array(2) { ["email"]=> string(34) "[email protected]" ["displayName"]=> string(20) "xxxxxxxxxxxxxxxxxxxxxx" } ["organizer"]=> array(3) { ["email"]=> string(52) "[email protected]" ["displayName"]=> string(24) "xxxxxxxxxxxxxxxxxxxxxxxx" ["self"]=> bool(true) } ["start"]=> array(2) { ["dateTime"]=> string(25) "2013-09-17T20:00:00+09:00" ["timeZone"]=> string(10) "xxxxxx/xxxxxxxxxx" } ["end"]=> array(2) { ["dateTime"]=> string(25) "2013-09-18T21:00:00+09:00" ["timeZone"]=> string(10) "xxxxxxxx/xxxxxxxxxxxxx" }
: 여기
[{"title":"c","start":"c"},{"title":"\"","start":"\""},{"title":"T","start":"T"},{"title":"","start":""},{"title":"2","start":"2"},{"title":"A","start":"A"},{"title":"r","start":"r"},{"title":null,"start":null}]
이
var_dump($eventsCalendar);
의 결과의 한 부분이다
이
내 코드입니다다음은 print_r($eventsCalendar)
의 결과입니다.
Array ([kind] => calendar#events [etag] => "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" [summary] => xxxxxxxxxxxxxxxxxxxxxxxx [description] => [updated] => 2013-09-06T10:35:34.449Z [timeZone] => xxxx/xxxxx [accessRole] => reader [items] => Array ([0] => Array ([kind] => calendar#event [etag] => "xxxxxxxxxxxxxxxxxxxxxxxxxx" [id] => xxxxxxxxxxxxxxxxxxxxxxxxxxxx [status] => confirmed [htmlLink] => https://www.google.com/calendar/event?eid=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx [created] => 2013-08-24T00:44:24.000Z [updated] => 2013-08-29T05:33:04.171Z [summary] => xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx [location] => xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx [creator] => Array ([email] => [email protected] [displayName] => xxxxxxxxxxxxxxxxxxxxxxxxxxxx) [organizer] => Array ([email] => [email protected] [displayName] => xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx [self] => 1) [start] => Array ([dateTime] => 2013-09-03T20:00:00+09:00 [timeZone] => xxxxxx/xxxxxxxx) [end] => Array ([dateTime] => 2013-09-03T21:00:00+09:00 [timeZone] => xxx/xxx) [recurrence] => Array ([0] => RRULE:FREQ=MONTHLY;BYDAY=1TU) [visibility] => public [iCalUID] => [email protected] [sequence] => 1) [1] => Array ([kind] => calendar#event [etag] => "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" [id] => xxxxxxxxxxxxxxxxxxxxxxxxxxxxx [status] => confirmed [htmlLink] => https://www.google.com/calendar/event?eid=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx [created] => 2013-08-25T08:03:53.000Z [updated] => 2013-08-29T05:33:15.417Z [summary] => xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx [location] => xxxxxxxxxxxxxxxxxxxxxxxxxxxx [creator] => Array ([email] => [email protected] [displayName] => xxxxxxxxxxxxxxxxxxxx) [organizer] => Array ([email] => [email protected]om [displayName] => xxxxxxxxxxxxxxxxxxx [self] => 1) [start] => Array ([dateTime] => 2013-09-17T20:00:00+09:00 [timeZone] => xxxx/Txxxxxxxx) [end] => Array ([dateTime] => 2013-09-17T21:00:00+09:00 [timeZone] => xxxx/xxx) [recurrence] => Array ([0] => RRULE:FREQ=MONTHLY;BYDAY=3TU) [iCalUID] => [email protected] [sequence] => 0) [2] => Array ([kind] => calendar#event [etag] => "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" [id] => xxxxxxxxxxxxxxxxxxxxxxxxxxx [status] => confirmed [htmlLink] => https://www.google.com/calendar
저는 Google에서 JSON의 구조와 PHP 배열로 변환 할 때 표현되는 방식이 명확하지 않기 때문에 확신합니다.
어디에서 코드가 잘못 되었습니까? Google에서 얻은 JSON을 원하는 정보만으로 어떻게 제거 할 수 있습니까? 배열
json_decode(file_get_contents("url"), true);
이 이벤트 캘린더 응답 –
@NathanSrivi보기보십시오 반대하지로 – Questioner
print_r 결과를 넣어주세요 –