GCal Events is a module which will display upcoming events in a block. The source for these events is a Google Calendar.

Who is this module for?

  • If you want to simply and easily add a calendar to your Drupal site with minimal effort, this module is for you.
  • If you already have a Google Calendar for your organization and want professional-looking integration

How does it work?
GCal Events uses your public Google Calendar's ID and the Google Calendar API v3. This will show your upcoming events in Drupal block.

Features
Here are some of the interesting features built into GCal Events:

  • Can read from public or private google calendar
  • Multiple blocks can be set up, each configured independently.
  • Date/Time display format can be configured
  • Timezone can be configured (PHP 5.1 and higher)
  • Display uses templates, so each item (title, location, date, description, url, etc) can be configured for each block. Very flexible and powerful!
  • Customizable "footer" to include brief information about the calendar ("provided by so-and-so", "updated weekly", a link to the full calendar, ical feed link, etc)
  • Customizable "no upcoming events" text to display when no events are coming up.
  • Repeating and all-day events are handled
  • "Today Only" option to show only events occurring on this calendar day.

Installation

  1. Download this module
  2. Extract this module
  3. Upload this module
  4. Enable this module

See this page if you need general help installing modules into Drupal websites.

Configuration
Get a Google Developer ID key

  1. Navigate to https://code.google.com/apis/console.
  2. Create a project and turn on the Calendar API (agree to the TOS).
  3. Navigate to "Credentials" in the left menu under "APIs & auth".
  4. Create a new key (server key) if you don't already have one.
  5. Once it's created, it'll display on that page. Copy the "API KEY" and save it for later.

Get the Google API Client Library for PHP

  1. Navigate to https://github.com/google/google-api-php-client and clone the master branch.
  2. Rename that cloned directory "google-api-php-client" and move it to sites/all/libraries.

Configure your GCal Events blocks

  1. In the module configuration page, set the number of blocks to display.
  2. In the block configuration screen, configure block 0.
  3. Get the Calendar ID from google calendar and input as the calendar ID.
  4. Put the API Key you created into the "Developer ID" field.
  5. Still in the block configuration screen, set the block to an active region and save.
  6. Also check to make sure you have block caching enabled on the performance settings for your Drupal site.
    This will help keep you below the quota limits for the free API account.

How to get Google Calendar ID and Private ID
(Note: As of gcal_events.module version 1.5, you can just copy and paste the XML address and the Calendar ID and Private ID will be parse out automatically) If you are testing out the module and need a calendar to try, I recommend a Google Calendar ID of usa__en@holiday.calendar.google.com. That is a public calendar of US Holidays. It is guaranteed to always have a few upcoming events and should work in all cases.

  1. Log into your Google Calendar.
  2. Click on the "Settings" tab.
  3. Select "Calendars"
  4. Click on the calendar you want to use.
  5. In the section labeled "Calendar Address", you should see "Calendar ID". Copy and paste that ID. into the GCal Events configuration.

If you just fill in the Calendar ID, GCal Events will default to using your public calendar. Events marked as private will not show up. If you want to display your private
calendar (not advised):

  1. Under the section marked "Private Address", click on XML
  2. You will see a URL that looks something like this:
  3. http://www.google.com/calendar/feeds/somename%40gmail.com/private-0562849527c0abe35379accccb4ecfd4/basic

  4. For Private ID, you are looking for the section between "private-" and "/basic"

Template Customization
GCal Events was written to be a very flexible and customizable module. Rather than having people download the module and modify the code to meet their unique needs, I tried to write the module in a way that it can be configured to meet the majority of those needs.

Each Google Calendar XML feed contains events with the following fields:

  • Title (#TITLE#)
  • Location (#LOC#)
  • Date (#DATE#)
  • Time (#TIME#)
  • URL (#URL#)
  • Description (#DESC#)

In addition, GCal Events provides these modified fields for your use:

  • URL-Encoded Location (#LOCURL#)

An event block uses templates to display these fields in the format you specify. The Event Template is the template that combines all the fields together. You can add html tags or linebreaks as needed between elements.

In addition to the Event Template, each field has a template of its own which specifies what should be done to that field before including it in the Event Template

  • Title Template
  • Description Template
  • Date Template
  • Time Template
  • Location Template

Typically, you will want to keep the Events Template free of any customization that applies to a field individually, like a bold tag or linebreak tag. This is done so that if a field is missing from the XML feed, the extra linebreak will not be shown (for example, an all-day event will not have a time, so you do not want an extra blank line showing up for that).

Here are some example customizations:

  • To get the title to be a link to the event in google calendar:
  • Title Template: <b><a href="#URL#">#TITLE#</A></b><br>

  • To get the location to be a google map:
  • Location Template: <a href="http://maps.google.com/?q=#LOCURL#">#LOC#</A>

Time/Date Customization
Time and Date formats are very customizable. The default format for time/date display can be configured in the GCal Events administration page. Each block can also be configured to override that if you need a different display in a different block.

Timezone Configuration
On most systems, timezone configuration will not be needed. The "local time" according to the machine hosting your page will be what is used. If the machine is set up using UTC or a different timezone, you may need to select an alternate time zone to display the events correctly.

Feature Requests

  • Configurable look-ahead time for events: Set a maximum time to look for events (next 30 days, next 5 days, etc). Current behavior is to look for ALL future events
  • Current week/month/year only: Only display events from the current week, month, or year, rather than the next X events which might span a week/month/year border.
  • php code: Allow a block of custom php to be executed for the block or for each event. This is a potentially risky feature, and unless a really good reason comes along, I see no reason to add it.

If you want/need one of these features or think of another feature you could use, please let me know! It's possible that it is already possible and just needs to be configured. If not, there's a possibility that if you could benefit from a new feature, somebody else could as well, and that would make a worthwhile addition.

More Information

Authors

  • Originally written by Jeff Simpson
  • Adapted from code written by James Cridland

Please post issues/suggestions/etc on the GCal Events Project Page. Comments posted here might go months before anybody sees them.

Comments

rdolgina’s picture

Great module, works OK. Does anyone knows how often feeds are refreshed and if I can/should adjust settings? Another tricky question: if I have 2 gcals and need to duplicate block with different feed what to do?

jamiegrinnell’s picture

I don't know how to use this. I think the documentation needs to be explained better. How do I Create a cache directory that is writeable by the webserver (defaults to modules/gcal_events/cache)?

How do I Create an input filter to use for gcal_events (I recommend calling it gcal_events). You will most likely want this input filter to be accessible to anonymous users?

I'm lost and this documentation is very confusing. Please help

fischerj’s picture

How do I Create a cache directory that is writeable by the webserver

After uploading the module to your webserver simply create a new folder in '/modules/gcal_events' named 'cache'.

Caution: Make sure to set directory permissions for the cache directory and refuse public read access. Otherwise it might be possible for everybody to list your cache entries and get your public and private calender id.

jtreg’s picture

In the section labeled "Calendar Address", you should see "Calendar ID". Copy and paste that ID. into the GCal Events configuration.....

I cant find the "Calendar Address" field in GCal Events configuration... please clarify

iceph03nix’s picture

Instructions need to be updated. Simplepie has changed the way the provide their attachments, and it took me a good 30 minutes to find simplepie.inc. I had to go back through their github to find an old version that still had it.

ranjit.tilekar’s picture

I am trying to use #URL# to get the url for the event in the google calendar. But it doesn't return the url value. I tried to print it using #URL# but nothing gets printed on the page.

Please help

dvennens’s picture

Hi,

I followed the instructions discribed above but no events will show.
I don't get errors but my eventlist only shows voet (footer in english) so i think the connection with google works
but no events.

this is the html thats generated

#<div id="block-gcal-events-gcal-events-0" class="block block-gcal-events">#

<h2>Aankomende Wedstrijden</h2>

<div class="content">
<div class="item-list"><ul class="gcal_events"><li class="first"></li>
<li></li>
<li class="last"></li>
</ul></div>Voet</div>

</div>  </div>
drupalnewie @berfi’s picture

I want to obtain only the event from the current time as the following:
event 1
, 12:00am

event 2
, 6:00am

event 3
, 7:00am

event 4
, 10:00am

event 5
, 12:00pm

event 6
, 2:00pm

if the current system-time is 12:00pm it should display only event 5. The state should change to event 6 at 2.00pm. So i want only one event to display. Is it possible to achieve with the current configuration?

Thanks

fradaric’s picture

2. Configure your GCal Events blocks

1.In the module configuration page, set the number of blocks to display. -> doesnt say how many blocks needed!! ?

I dont find the following options to filll,
2. In the module configuration page, set the number of blocks to display.
3 The below options are not found, where do I keep the settings then?
4 In the block configuration screen, configure block 0.
5.
6. Put the API Key you created into the "Developer ID" field.

I am missing something? I installed Gcal and kept the clone file in libraries