Has anyone managed to get JSONDerulo working with Google Calendar?

I’ve been trying to see whether JSONDerulo can pull in events from a Google Calendar. It’s supposed to be able to but documentation is pretty light on the Google Cloud configuration aspects needed.

So far I…

And yet I get “No events”. And JSONDerulo doesn’t log anything so there’s no obvious way to see what’s wrong.

Anyone had any joy?

Hej @channel27,
i setup this for years and its still working now. Can you post your Snippet call?

This is mine:

[[!JSONDerulo?
    &feed=`googlecalendar`  
    &tpl=`jd.googleCalendar-nf`
    &limit=`20`
    &cacheTime=`300`
    &cacheName=`nfdates`						  
    &feedLocation=`****@gmail.com`     
&apiKey=`****SyAqXzqSDHLUPD0gDsdTSPpQP4ICkJlMz3*`  ]]

Here’s mine.

[[!JSONDerulo? &feed=`googlecalendar` 
   &tpl=`jd.googleCalendar` 
   &limit=`10` 
   &cacheTime=`5` 
   &cacheName=`c27_sched` 
   &feedLocation=`⬛⬛⬛@group.calendar.google.com` 
   &apiKey=`⬛⬛⬛` 
   &timeMin=`` 
   &random=`0` ]]

You know, my hunch is that the snippet is fine but there’s a problem with getting the data out of Google Cloud. But there’s no error log entries so rather flying blind.

Hej @channel27,
the Snippet try to fetch this URL. Can you replace the Placeholders with your credentials und test the result in the Browser?

https://www.googleapis.com/calendar/v3/calendars/{feedlocation}/events?key={apiKey}&orderBy=startTime&singleEvents=true&maxResults={limit}&timeMin={timeMin}

Should look like this:

https://www.googleapis.com/calendar/v3/calendars/****5d3b09a5fae4747631b1750eaa1b80228d15b3541ca102597bc7781b2@group.calendar.google.com/events?key=***CcenNDr8vMh3mwG6TSvV1Iy6ZwPHSpX58&orderBy=startTime&singleEvents=true&maxResults=10

Here is my result:

In this Google Cloud Console i add the following to the API Key:

This is my working Snippet call for the test:

[[!JSONDerulo?
	&feed=`googlecalendar`
	&tpl=`jd.googleCalendar2`
	&limit=`100`
	&cacheTime=`1`
	&cacheName=`dates`
	&feedLocation=`******3b09a5fae4747631b1750eaa1b80228d15b3541ca102597bc7781b2@group.calendar.google.com`
	&apiKey=`*****8vMh3mwG6TSvV1Iy6ZwPHSpX58` ]]

We’re getting somewhere - thank you.

The direct call by itself only returns events from 2014 (when the calendar was first created). After some tweaking I found that removing the limit in the snippet rendered 10 upcoming items. Thus the snippet became boiled right down to:

[[!JSONDerulo? &feed=`googlecalendar` &tpl=`jd.googleCalendar` &limit=`` &cacheTime=`5` &cacheName=`c27_sched` &feedLocation=`⬛@group.calendar.google.com` &apiKey=`⬛`]]

The problem then comes up that if you want say a week’s worth of events, you’d probably want to set the limit to 30 or something and if you set that, you’ll get nothing back. It looks like the ‘timeMin’ which is supposed to default to NOW isn’t actually doing so. Because if you make a direct call to…

https://www.googleapis.com/calendar/v3/calendars/⬛@group.calendar.google.com/events?key=⬛&orderBy=startTime&singleEvents=true&maxResults=10&timeMin=2024-01-03T10:00:00-07:00

…you get a plausible set of results back

@channel27 you could change the URL in the Snippet a this line (make a copy first :wink: ) and change the date part?

JSONDerulo/v2/snippet.JSONDerulo.php at b302ca1f11afb410f9166abb63f6b71c2ca33988 · pdincubus/JSONDerulo · GitHub

Or maybe you can skip JSONDerulo completely (because its no longer maintained) and make a custom snippet by using for example something like this:

<?php
# vars
$pdo = $modx->getService('pdoTools');
$apiUrl = "{apiUrl}";
$lifetime = 60 * 60;
$chunkName = "calendarItem";
$cacheKey = "calendar";
$output = $modx->cacheManager->get($cacheKey);

if (!$output) {
  $data = file_get_contents($apiUrl);
  $json = json_decode($data, true);
  foreach ($json["items"] as $item) {
      $output .= $pdo->getChunk($chunkName, $item);
  }
  $modx->cacheManager->set($cacheKey, $output, $lifetime);
}

return $output;