Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script cannot access Calendar API (with default oauth key(?)) #87

Closed
koorg opened this issue Oct 11, 2017 · 22 comments
Closed

Script cannot access Calendar API (with default oauth key(?)) #87

koorg opened this issue Oct 11, 2017 · 22 comments
Assignees
Labels
help request Issues raised by users who had problems running the script. solved The problem has been solved and the code is waiting to be deployed in production.

Comments

@koorg
Copy link

koorg commented Oct 11, 2017

Sadly it seems that noone else had this issue before (open/closed issues)...
I cross-checked the set-up and it seems that I have a strange case with the script trying to access the Calendar (yeah it feels like deja-vu)

Steps to reproduce

What action or series of actions is the cause of the issue?

  1. followed every setup step including customization and optional settings, enabled all 3 event types (birthday, anniversary, other)
  2. set a fake date to the previous day of an anniversary which is visible in my calendar
  3. run / test

Expected behavior

Receiving a notification

Current behavior

Error: Contacts events calendar not found! Please follow the instructions (step "Enable the calendar"). (line 551, file "Code")

Context

  • Version of the script: 3.1.1
  • Checked steps :

When script in being edited : menu Resources -> Advanced Google Services
Calendar API (v3) in enabled
Going to Google API Console shows "Google Calendar API" enabled, with no activity.
Entering the Google Calendar API settings, the drop-down "all API identifiers" shows the "oauth" script URL enabled under the title "Apps Script" type "ID for Web App" with a callback URL of https://script.google.com/oauthcallback

BUT there is a banner on top of the Calendar API page that says "to use this API you need to create identifiers" and the drop-down documentation says it needs an API key...

I tried to create an API key and enable it for the Calendar API, but it doesn't seem I can have the script use it...

I tried to enable the Contacts API for a comparison, and it takes the oauth key by default (like the Calendar API) but doesn't display the "you need an API key" banner. I disabled it afterwards because it doesn't seem to be required to run the script.

Thanks for any help !!

@GioBonvi GioBonvi self-assigned this Oct 11, 2017
@GioBonvi GioBonvi added the help request Issues raised by users who had problems running the script. label Oct 11, 2017
@GioBonvi
Copy link
Owner

Hello @koorg

The errors seems not to be caused by APIs not being correctly enabled (it should throw a different one), but by the var calendarId not being correct. Can you double-check that you copied the correct value in it following the instructions directly above the variable?

    /*
     * ID OF THE CONTACTS EVENTS CALENDAR
     *
     * Open https://calendar.google.com, in the menu on the left click on the arrow next to the
     * the contacts events calendar (which should have a name like 'Birthdays and events'), choose
     * 'Calendar settings' and finally look for the "Calendar ID field" (it could be something
     * similar to the default value of '#contacts@group.v.calendar.google.com', but also really
     * different from it): copy and paste it between the quotes in the next line.
     */

Thank you

@koorg
Copy link
Author

koorg commented Oct 11, 2017

Oh damned.
I think I had to read it 10 times to have it correctly, it really feels like it had the default value "#contacts@group.v.calendar.google.com" even after I checked it some minutes ago, but for some reason my eyes now read it correctly "addressbook#contacts@group.v.calendar.google.com".
I swear I thought it was the default value some time ago... but will probably never be sure.
Perhaps the value was refreshed when I changed some settings like Calendar language and stuff... or perhaps it was always here before my eyes but couldn't read what was written before the #.

Testing at the moment... aaaand it works like a charm.
Thanks for the blazing fast help.

@GioBonvi GioBonvi added the solved The problem has been solved and the code is waiting to be deployed in production. label Oct 11, 2017
@koorg koorg closed this as completed Oct 11, 2017
@GioBonvi
Copy link
Owner

You are welcome @koorg.

@baatochan @rowanthorpe Throwing here a little thought I made while solving this issue.
Do you think it's better to:

  • have a default calendar ID in the script (as it is now):
    • Positive: many users will not need to copy/paste anything as it will already be correct.
    • Negative: some users might misread the value, causing an error (like in this issue).
  • have a blank calendar ID in the script:
    • Positive: All users will have to copy their values, reducing the possibility of an error.
    • Negative: This will require some more work for the users.

@baatochan
Copy link
Contributor

Can we somehow predict which users can have a different value than addressbook#...?

@rowanthorpe
Copy link
Collaborator

...this all looks very familiar :-D

@rowanthorpe
Copy link
Collaborator

Seeing that old PR, and this issue, it seems Google must use some transitory setting when (perhaps?) pivoting a software-update into production(?), updating DB schemas(?), or something. If so, then it seems unless we find a different way to access the calendar, someone somewhere will always get hit by this if they are unlucky...

@rowanthorpe
Copy link
Collaborator

...to clarify, when I opened that old PR, my calendar settings had changed to addressbook#... from just #..., and then a while later it changed back again by itself. It seems that is what is happening here too for @koorg

@rowanthorpe
Copy link
Collaborator

BTW: @koorg, are you using Google Suite (a.k.a. Google Apps - with custom domain-name)? or just gmail? - I ask because I am on Google Suite, and it would be good to narrow down if this applies only to Google Suite users or not.

@GioBonvi
Copy link
Owner

...this all looks very familiar :-D

Yeah, that was exactly what I was thinking of: I was going to link that when I received the notification of your comment.

unless we find a different way to access the calendar

There actually is an API call to list all the calendars of the user (with IDs, names and so on), but the ID has this addressbook/non-addressbook problem and the name changes with the language (and the user can rename it as well), so I see no way to automatically acquire the right calendar.

Maybe we could add this check:
Get all the IDs of all the calendars: if the ID specified in the settings by the user is not in the list then the user has done something wrong and we can alert them with a specific message.
If you find this helpful I can try implementing it.

@koorg
Copy link
Author

koorg commented Oct 11, 2017

@rowanthorpe not that I know of... I use multiple apps from google but I never heard of Google Suite.
After googling it, I can say I'm not a Gsuite user

@koorg
Copy link
Author

koorg commented Oct 11, 2017

@GioBonvi https://developers.google.com/apps-script/advanced/calendar could it be a workaround to use "listCalendars" from this page, and select the first one matching "#contacts@" or "@groups.v......."

@rowanthorpe
Copy link
Collaborator

rowanthorpe commented Oct 11, 2017

@koorg: OK, thanks for reply about Google Suite. So that means this affects all users including gmail users.

Perhaps a hybrid of both suggestions would be good. Meaning: to allow explicit configuration of the calendar ID (and to error out if it doesn't match an existing ID, as per @GioBonvi's suggestion), and to also allow the ID to be a special value for those who want it (like e.g. @@internal-heuristic@@) which would instead cause the script to do what @koorg suggests (and also error out if it can't find any ID contender). As for which should be the default - hmm, dunno.

For the case of erroring-out, it would be a good approach to output a meaningful log (and send an alert email) stating something along the lines of:

Your configured calendar ID doesn't presently exist. Google has been know to occasionally (very rarely) change Birthday calendars' IDs temporarily, e.g. from #contacts@group.v.calendar.google.com to addressbook#contacts@group.v.calendar.google.com for a day or two (perhaps during some internal deployments requiring pivoting of data). If your change looks like that perhaps you can just either wait a day to see, or use the @@internal-heuristic@@ value to attempt to deal with it automatically, otherwise if the change seems permanent (you receive this message many times in a row) please update the configuration at the top of your script to match the new calendar ID.

@baatochan
Copy link
Contributor

Google has been know to occasionally (very rarely) change Birthday calendars' IDs temporarily, e.g. from #contacts@group.v.calendar.google.com to addressbook#contacts@group.v.calendar.google.com for a day or two (perhaps during some internal deployments requiring pivoting of data).

I'd like to point out that I have the address of this calendar as addressbook#contacts@group.v.calendar.google.com all the time (I'm Google user since 2007 if that's important and I have never used Google Apps (or Google Suite; don't know how it's called right now)).

@GioBonvi
Copy link
Owner

@GioBonvi https://developers.google.com/apps-script/advanced/calendar could it be a workaround to use "listCalendars" from this page, and select the first one matching "#contacts@" or "@groups.v......."

Yes, that is exactly the API call I was referencing.
I like @rowanthorpe's approach: it's complete and should reduce the workload of all the users. Maybe we could use "empty" string as @@internal-heuristic@@. (empty string => try and guess, some string => use this as ID, with checks)

I'll try implementing it this afternoon/evening (I'll also do a final check on the approved PRs and merge them).

@rowanthorpe
Copy link
Collaborator

Based on what @baatochan just pointed out, I now suspect the addressbook prefix is a side-effect of another setting somewhere (probably a Google Calendar/Contacts setting). Perhaps I triggered that prefix back in May by changing the setting, and it reverted when I changed the setting back - but there is no way I could remember what that was, if so. @koorg, did you change a significant Calendar setting (or Contacts, or Google+, or...) just before the script started failing? As for a guess: I just noticed the Birthday Calendar settings includes a radio-button for Google+ circles & contacts or Contacts only. Maybe that (or something like it) affects the ID having the prefix or not?

@GioBonvi
Copy link
Owner

@rowanthorpe You got it!

Selecting "Contacts only" prepends "addressbook" to the calendar id!

@rowanthorpe
Copy link
Collaborator

BTW: If it is possible to lookup a calendar by its description(?) then there is a non-ambiguous way to do it - users can't edit the description. If the API allows looking up the description with a forced locale, then it could just be looked up as English, and there wouldn't even be a need to worry about parsing different translations. Of course, if the user wants to be a smartass and create their own calendar with the exact same description, then obviously they are trying to break the script, and we wouldn't need to cater to that edge-case.

@koorg
Copy link
Author

koorg commented Oct 11, 2017

@rowanthorpe Indeed, I changed some Calendar settings. But at first I had default settings with English(US) lang set, and the script didn't seem to work, and Calendar ID seemed to be the default one without addressbook#.
THAT'S IT
As you said :
"display birthday from == Contacts AND Google+ circles" => Calendar ID == "#contacts@group.v.calendar.google.com"

"display birthday from == Contacts only" => Calendar ID == "addressbook#contacts@group.v.calendar.google.com"

@baatochan
Copy link
Contributor

Oh yeah, I use "contacts only" setting as well :)

I haven't thought it could be that.

So if that's a case maybe we can set the script to test the calendar that is provided in calendarID and if it fails just check the second one?

@rowanthorpe
Copy link
Collaborator

I still think the hybrid-idea of (1)heuristic, or (2)explicit-with-existing-ids-check, and email-a-warning-on-error is worth implementing, so we can handle (A) people who like to opt-in to explicit-mode for security-reasons, and (B) the next naming-change Google makes in the future. Our discovery about the cause of the addressbook prefix, just allows us to use better defaults.

On another note - perhaps a lot of "optional Google+" handling could be removed from the script by instead getting that "Google+ & Contacts" vs. "Contacts only" setting via API (if possible), and acting according to that...?

@baatochan
Copy link
Contributor

On another note - perhaps a lot of "optional Google+" handling could be removed from the script by instead getting that "Google+ & Contacts" vs. "Contacts only" setting via API (if possible), and acting according to that...?

I'm not a fan of this idea - even though I use 'contacts only' setting I still want those contacts that are in my list to have data from G+.

@rowanthorpe
Copy link
Collaborator

@baatochan Ah, OK. Fair point. We should accommodate that use-case.

@GioBonvi GioBonvi mentioned this issue Oct 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help request Issues raised by users who had problems running the script. solved The problem has been solved and the code is waiting to be deployed in production.
Projects
None yet
Development

No branches or pull requests

4 participants