3

I need to access a NON-public Google calendar WITHOUT requiring the user to log in or even have a Google account.

I created an Android app that accesses a Google calendar using a service account:

        GoogleCredential credential = new GoogleCredential.Builder()
                .setTransport(httpTransport)
                .setJsonFactory(jsonFactory)
                .setServiceAccountId(serviceAccountID)
                .setServiceAccountScopes(scopes)
                .setServiceAccountPrivateKeyFromP12File(licenseFile)
                .build();
        com.google.api.services.calendar.Calendar.Builder builder = new com.google.api.services.calendar.Calendar.Builder(httpTransport, jsonFactory, credential);
        builder.setApplicationName(appName);
        com.google.api.services.calendar.Calendar client = builder.build();

        com.google.api.services.calendar.Calendar.Events.List list = client.events().list(calendarID);
        list.setMaxAttendees(maxAttendees);
        list.setTimeZone(timeZone);
        list.setTimeMin(startTime);
        list.setTimeMax(endTime);
        list.setOrderBy(orderBy);
        list.setShowDeleted(showDeleted);
        list.setSingleEvents(true);
        Events events = list.execute();

This included:

  1. Creating a project in the Google App console
  2. Creating a Service Account
  3. Giving the Service Account access rights to the Google calendar

It works GREAT!

I need to do the same thing in IOS. I have read every question/answer I can find on this topic and have found VERY different answers. Many say that Google hasn't allowed this in the IOS SDK because service accounts are intended to be used by server-based applications. I don't agree since the functionality I need is available in Android. So, now what?

The use case is this: My IOS app needs to access a Google calendar. That part is not too tough if you are okay with using OAuth. My problems with this approach are:

  • Requires to user to have a Google account. Many of my users are Apple-Only. I can't require them to get a Google account just to use my app.
  • I can't make the calendar public. So, I would need to give access to every new user. I guess I could do that with a web-based application but this doesn't fix the problem (refer to previous problem - no Google account).

I really need to be able to query the events in the NON-public Google Calendar WITHOUT the user needing a Google account. The solution IS using a "Service Account" (I think).

I read one question/answer that said this is possible but the solution was never posted. (How to list Google Calendar Events without User Authentication)

HELP!!!!

Community
  • 1
  • 1
JustLearningAgain
  • 2,227
  • 4
  • 34
  • 50

1 Answers1

1

The official documentation suggests that if you want to handle Calendar API (for example), you'll have to have a Google Apps for Work (source).

If you have a Google Apps domain—if you use Google Apps for Work, for example—an administrator of the Google Apps domain can authorize an application to access user data on behalf of users in the Google Apps domain. For example, an application that uses the Google Calendar API to add events to the calendars of all users in a Google Apps domain would use a service account to access the Google Calendar API on behalf of users.

Once the prerequisite is met, you can try to just call the REST URLs of Calendar API based on your implementation (since there seems to be no iOS support or samples available in the documentation).

adjuremods
  • 2,938
  • 2
  • 12
  • 17
  • In fact, I am using a Google Apps domain with Google Apps for Work. So, I think the prerequisites have been met. Could you give me some sample code showing how to use the REST URLs. I've tried using Advanced REST Client (Chrome add-on) using a GET with the following. I tried the following and got a maximum number of attempts failure: GET https://www.googleapis.com/calendar/v3/calendars/heathwallace.com_gpupieshkuc85dd832m9gjrh9g%40group.calendar.google.com/events?key={YOUR_API_KEY}. I'm lost. I need a code example or a screenshot of the tool I talked about above. – JustLearningAgain Jan 07 '16 at 02:46
  • You can check out the Service Accounts page for sample API calls in REST. The Advanced REST Client may be a bit tricky since the REST calls needs authorization. Hopefully this will help with what you need. – adjuremods Jan 07 '16 at 08:05
  • Do you have any sample code showing how to make this work? I have looked at the page you referenced (before and after reading your post). The problem is that is seems very convoluted. The code that's there is for Google Drive and not Calendar although I know they are very similar. I'd really like a simple method that shows all the steps. Even though you answer goes in a different direction, I'd mark this as the answer if I could make sure that me (and everyone else having this issue) has a simple source example walking them through the steps. THANKS!!! – JustLearningAgain Jan 10 '16 at 22:16