The Strategy Space


Blog home »

Seminar Calendar Tutorial

May 28, 2023

In my early years as a PhD student at UW, James Lee revamped the theory website into its current glorious state. One of the coolest things (in my opinion) about this website is the list of upcoming "theory talks" right at the top. Date, speaker, title. And if you click on it, you get an abstract and location. The most beautiful part? This is actually a google calendar, so (1) you can subscribe to it, if like me, you can't function without everything on your calendar, and (2) it's all updated just be editing the calendar—no need to modify the website itself and push changes. If a student is in charge of the seminar, you can just share calendar editing privileges with them for the semester.

I've since been at Columbia and BU and copied the general idea of this extremely useful and informative website, adding this calendar to both. A very long time ago, James suggested that maybe if we ever had time, we could make a guide so others knew how to do this. In honor of James initially setting up this infrastructure, here we go.

The first step is to embed the google calendar using javascript. James's original calendar code as the following link (and note that he wrote it in a single pass, and it's not particularly responsive e.g. on mobile devices, so please feel free to improve on it):

http://theory.cs.washington.edu/js/cal.js

Quoting what James initially told me, "It produces (dynamic) HTML in a fairly straightforward way, except that for the "accordion" effect, it using bootstrap. (Bootstrap is a light-weight CSS framework designed to dynamically adjust to different media types.) There are a few weird hacks in there, like if an event is "full day" (no specified start time) then Google often gets the day wrong when it tries to interpret the start date in the local time zone, and I found that adding 1HR to the start time fixes most issues."

The more difficult part is in obtaining a clientID and an API Key from google, and you may want to create a new Google login for this purpose. The following instructions are based originally on the following article, but have been updated with my more recent experience, as Google's interface as been updated. I last did this about a year ago, so I apologize if it's out of date again.

How to get an API Key:


Sign in to your Google account. Go to https://console.developers.google.com/project and click "Create Project."

Screenshot: the Create Project button in the Google API console

Enter a project name—you don't need to change anything else. For this example, I'm using "BU-theory-cal"

Screenshot: entering the project name

Click "Create" and then wait for the project to be created. When it's done, you should see a notification badge at the top right of your screen. Click on the project from here.

Screenshot: the notification badge listing the newly created project

Scroll to the bottom of the page and click "Explore and enable APIs."

Screenshot: the

Click "Enable APIS and Services."

Screenshot: the

Click in the Search field and type "Calendar."

Screenshot: typing

Click the "Google Calendar API" from the search results.

Screenshot: the Google Calendar API in the search results

Click the "Enable" button.

Screenshot: the Enable button on the Google Calendar API page

Click the "Credentials" link on the left.

Screenshot: the Credentials link in the left-hand menu

Click "Create Credentials."

Screenshot: the Create Credentials button

Click "OAuth client ID."

Screenshot: choosing OAuth client ID from the credentials menu

Click "Configure Consent Screen."

Screenshot: the Configure Consent Screen button

Check "External" and click "Create."

Screenshot: choosing the External user type and clicking Create

Fill in your app information—this will not wind up being visible to anyone, so it is not really important.

Screenshot: the App information fields on the consent screen form

The domain needs to be private (not .edu or .org) and top level, so use a domain owned by you or someone on your team. This is not where the calendar needs to be hosted.

Screenshot: the App domain fields on the consent screen form

Click "add or remove scopes."

Screenshot: the

We'll add a single API scope found on the third page that just has "See the events on public calendars"—check this one and add.

Screenshot: selecting the

Go and click the "Create credentials" button again, and from the dropdown, you should now be able to click API key

Screenshot: choosing API key from the Create credentials dropdown

An API key will be generated. Enter a new name in the "Name" field. For example I am using "BU Calendar API key 1." In the "Application restrictions" section, click "HTTP referrers (web sites). In the referrers entry field, you can restrict to your website, e.g., I restrict to *.bu.edu/* to restrict to only websites on BU's domain.

Screenshot: restricting the key to HTTP referrers on a chosen domain

Under API restrictions, click "Don't restrict key" and then click "save."

Screenshot: choosing “Don’t restrict key” under API restrictions

Your API key has been created now, and you need to copy it so you can install it.

Click the copy icon next to the API key to copy it to your computer's clipboard.


Creating a client ID:



Now we'll create an OAuth client ID. Go to "Create Credentials" one last time and select "OAuth client ID" from the drop-down this time.

Screenshot: selecting OAuth client ID from the credentials dropdown a second time

Select "Web application" under "Application type" and give it a name—I've chosen "BU Calendar Web client 1." Add in the base url of your domain, which for me is https://www.bu.edu despite the fact that I will actually use it at a lower level of the domain.

Screenshot: naming the OAuth client and entering the base URL of the domain

Click "Save."

Your OAuth client ID has also been created—again click the copy icon next to the OAuth client ID to copy it to your computer's clipboard.


Finishing Up:



You will also need your google calendar's ID. To do that, give the relevant Google account admin access to the calendar. Go into Google Calendar, look under "My Calendars" on the left, and click on the three dots beside the calendar you want. Go to "Settings and sharing." If you scroll down, you will see the "Calendar ID." That's what goes in the clientID variable in the code.

(From here, you can also ensure that the calendar is visible to the public, and that appropriate people have write access to add events.)

If you did all that, the calendar code should now work (but only on the website you allowed for with the APIkey, and only live). It's okay that the clientID and APIkey are world-readable. Then just allow read access to the (public) calendar.

Blog home »