Google Calendar API server side access

家住魔仙堡 提交于 2020-02-02 17:20:23

问题


I implemented an utility to perform background operation using Google Calendar API and server side authentication flow without user interface. Now I would like to read events from a private calendar without using authorization flow with offline access or put calendar public.

I'm using this code for authentication:

GoogleCredential credential = new GoogleCredential.Builder()
            .setTransport(SchedulerCalendar.HTTP_TRANSPORT)
            .setJsonFactory(SchedulerCalendar.JSON_FACTORY)
            .setServiceAccountId(SchedulerCalendar.SERVICE_ACCOUNT_EMAIL)
            .setServiceAccountScopes(SchedulerCalendar.SCOPES)
            .setServiceAccountPrivateKeyFromP12File(new File("key.p12")).build();

And the following for read calendar events:

List eventslist = calendar.events().list(calendarid);

The response is 404 for calendar not found.

Any suggestion?


回答1:


I solved my problem sharing the calendar to the *@developer.gserviceaccount.com, and I added http://www.google.com/calendar/feeds/ to scope of the request.

The calendar that I'm using is also from a google apps user so I add also my account *.apps.googleusercontent.com -> http://www.google.com/calendar/feeds/ to Manage API client access from google apps control panel.



来源:https://stackoverflow.com/questions/16670032/google-calendar-api-server-side-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!