First and foremost - I am not a PHP developer. I concentrate on front-end but am wanting to expand my knowledge/play around with some personal projects to further my understanding. Therefore some of my terminology and fundamental understand of what I'm trying to achieve may be a little ... 'off'.
I have followed all the steps provided by Google and have managed to get to a point with the Google Calendar API where I can list calendar events using a simple var_dump()
My problem lies in trying to make this data useful. I want to do this with JSON. I am aware of the json_encode()
function but am not sure how I should be using it within the context of what I am trying to achieve (that is to have a JSON file which can hook into the data I need to ultimately display a calendar on the front-end). I am aware that json_encode()
respects property visibility/scope but this is my problem - I cannot figure out how to ensure json_encode()
will also encode the protected properties/methods in the object I am returned.
Here is my code:
$eventsArgs = array(
'maxResults' => 10,
'singleEvents' => true,
);
$events = $calendarService->events->listEvents('***@gmail.com', $eventsArgs);
$listEvents = fopen('list_events.json', 'w');
foreach($events->getItems() as $event) {
fwrite($listEvents, json_encode($event, JSON_PRETTY_PRINT));
}
fclose($listEvents);
I am wanting to pull in protected properties/methods such as start
and end
as displayed here with a simple var_dump()
...
["modelData":protected]=> array(5) {
["creator"]=>
array(3) {
["email"]=>
string(23) "***@gmail.com"
["displayName"]=>
string(14) "***"
["self"]=>
bool(true)
}
["organizer"]=>
array(3) {
["email"]=>
string(23) "***@gmail.com"
["displayName"]=>
string(14) "***"
["self"]=>
bool(true)
}
["start"]=>
array(1) {
["dateTime"]=>
string(25) "2014-04-27T05:00:00+01:00"
}
["end"]=>
array(1) {
["dateTime"]=>
string(25) "2014-04-27T06:00:00+01:00"
}
I am really trying to educate myself here and unfortunately have hit a wall and the answers I find, if I'm honest, are a little too technical for my understanding. Technical as well as non-technical explanations welcome!
Thanks for reading.