0

I am attempting to create Google Calendar events as per the code given at here. I've narrowed the probem down to an authentication issue in the following call:

gapi.auth.authorize({client_id: clientId, scope: 'https://www.googleapis.com/auth/calendar', immediate: true}, handleAuthResult);

which does not return an access token. The returned auth object looks like this:

client_id: "xxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com", cookie_policy: undefinederror: "immediate_failed", error_subtype: "access_denied"expires_at: "1432593971"expires_in: "86400"g_user_cookie_policy: undefinedissued_at: "1432507571"response_type: "token"scope: "https://www.googleapis.com/auth/calendar"state: ""

I know my calendar configuration is correct (i.e. client_id) because as I can pull events and place them into a list see example. This is because reading events doesn't require OAuth 2.0 - it only requires a public api key.

Furthermore, I am able to create events programatically using this Java API by supplying only my client_id. Notice the magic button near the bottom which offers to authorize requests using OAuth 2.0. When I enable this everything works fine. So the question is how is this done programatically in a JavaScript/browser environment?

Community
  • 1
  • 1

2 Answers2

1

I had discovered that popups were blocked in my browser and this prevented the authentication process from completing. Once I enabled popups, the process was able to complete successfully. Doh! The code was complete and OK after all.

0

Wierd. Looks like Google doesn't like your credentials.

  1. Have you remembered to call gapi.client.setApiKey(apiKey) before trying gapi.auth.authorize()?

  2. Are apiKey and clientId both defined and in scope? If you're not sure, try sticking alert(apiKey + '\n' + clientId) or console.log(apiKey, clientId) in the same function.

j-da
  • 188
  • 10
  • I've created a simple running example [here](http://creativecomputerlab.com/simplecalendar.html) which pulls events but cannot insert them. It runs automatically when loaded. Check the console output for results. Everything has been double-checked as suggested by @j-da. Also, I've added the service account email address to the list of calendar users and gave it full permissions. – BurrenLowlands May 25 '15 at 08:59