2

I have a google calendar that I have set up as public, I want to build a web app so that anyone can see the availabilities and can insert an event. I am using javascript, the retrieving of the availabilities works fine, I have followed this link https://developers.google.com/calendar/quickstart/js I am stuck at the insert' I want to be able to insert event, without any authentication, how can I do that ? here is my code:

function insert() {
  var event = {
    'summary': 'Google I/O 2015',
    'location': '800 Howard St., San Francisco, CA 94103',
    'description': 'A chance to hear more about Google\'s developer products.',
    'start': {
      'dateTime': '2020-01-28T09:00:00-05:00'
       'timeZone': 'America/Los_Angeles'
    },
    'end': {
      'dateTime': '2020-01-28T10:00:00-05:00'
      'timeZone': 'America/Los_Angeles'
    },
    // 'recurrence': [
    //   'RRULE:FREQ=DAILY;COUNT=2'
    // ],
    'attendees': [
      {'email': Email@example.com'}
    ],
    'reminders': {
      'useDefault': false,
      'overrides': [
        {'method': 'email', 'minutes': 24 * 60},
        {'method': 'popup', 'minutes': 10}
      ]
    }
  };

  var request = gapi.client.calendar.events.insert({
    'calendarId': 'myCalendarID',
    'resource': event
  });

  request.execute(function(event) {
    appendPre('Event created: ' + event.htmlLink);
  });

}

Thanks

Lydia halls
  • 652
  • 8
  • 17
  • Where's your code? – GetSet Jan 26 '20 at 02:55
  • Just added it :) – Lydia halls Jan 26 '20 at 03:01
  • The example link you provide "quickstart" mentions that authentication is required. Are you hoping for a workaround where you could skip that section of the tutorial? – GetSet Jan 26 '20 at 03:08
  • I do not have to authenticate, as long as the Calendar is set as public, and it worked. My problem now is the update\insert. – Lydia halls Jan 26 '20 at 03:11
  • Your problem might be that. Or your problem may be that you're not authenticated. Refer to this SO thread. https://stackoverflow.com/questions/18064149/accessing-a-public-calendar-using-google-api-without-requiring-a-user-to-log-in .. Even tho the topic of nodejs is discussed, note the accepted answer where it states *All requests to the Google Calendar API must be authorized by an authenticated user*. Maybe in your case viewing of a public calendar is fine without auth. However now you wish to make changes to that calendar correct? – GetSet Jan 26 '20 at 03:20
  • Ok, so if I understand, we can read (without authentication) bu we cannot write ! – Lydia halls Jan 26 '20 at 03:25

1 Answers1

0

I got the answer for that, the solution is to use service account: https://developers.google.com/identity/protocols/OAuth2ServiceAccount Hope this help

Lydia halls
  • 652
  • 8
  • 17