2
votes

I'm writing a watchapp for Pebble to show events from the Google calendars.

I'm using Auth 2.0 to authenticate the user as described in this document.

Then I retrieve events using this API v3 call, specifying my access_token in the authorization header.

For the calendars created and managed by the user everything works fine.

However if I try to get the events from the Google+ calendars, such as Birthdays (#[email protected]) or Holidays in Italy (en.italian#[email protected]), the answer is 404:

   {
        "error": {
            "errors": [
                {
                    "domain": "global",
                    "reason": "notFound",
                    "message": "Not Found"
                }
            ],
            "code": 404,
            "message": "Not Found"
        }
    }

What am I doing wrong? Or is it a bug of the Calendar API?

1
It could be an escaping issue. You can check in the API explorer that retrieving events from these works just fine: developers.google.com/apis-explorer/#p/calendar/v3/… (don't forget to authenticate in the top right corner)luc
Yeah sorry! I forgot to mention that from the API explorer I can successfully retrieve the events from these calendars. What do you mean with 'escaping issue'?wverdese
I've figured it out just now. Using encodeURIComponent on the calendarID it finally works! You saved my day luc, thank you very much!wverdese
Cool, thanks for letting me know. It would be great if you pasted your fixed code as the answer ;)luc

1 Answers

1
votes

Thanks to luc, here's the answer!

I was calling the service this way:

var GET_EVENT_LIST = "https://www.googleapis.com/calendar/v3/calendars/%s/events";

var calendarId = "#[email protected]";
var token_type = "Bearer";
var access_token = "...";

var url = sprintf(GET_EVENT_LIST, calendarId);

var req = new XMLHttpRequest();
req.open("GET", url, true);
req.setRequestHeader("Authorization", token_type + " " + access_token);
req.send(null);

I solved changing the fifth line to:

var url = sprintf(GET_EVENT_LIST, encodeURIComponent(calendarId));