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?
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.
Wierd. Looks like Google doesn't like your credentials.
Have you remembered to call
gapi.client.setApiKey(apiKey)
before tryinggapi.auth.authorize()
?Are
apiKey
andclientId
both defined and in scope? If you're not sure, try stickingalert(apiKey + '\n' + clientId)
orconsole.log(apiKey, clientId)
in the same function.