GET/ADD Events to google calendar with a service account

人走茶凉 提交于 2019-12-12 04:06:08

问题


I have to access a google calendar from a java webapplication to get and especially add events to a shared google calendar I followed the java quickstart example from google and everything works fine so far

then I changed the authorize method in that example to use a service account and the authentication seems to work but the calendar List returned from google is empty

I already shared the calendar with the service account email but that doesnt change anything


回答1:


Service account is a dummy user. It has its own Google Calendar account. By default it doesn't have access to any Google Calendars you need to either share a google calendar with it or insert a new Google Calendars into it.

Calendar.list is something else entirely its basically the little box at the bottom left in the Calendars website. In order for a calendar to appear there it I needs to be inserted into the calendar.list.

Solution:

Go to the Google calendar website add the service account email address as a user of your calendar. Then the service account will be able to access it. If you want you can programmatically insert it into calendar.list if you really need it to be there. IMO there is really not much point for Calendar.list with a service account.

update

You should be able to grant your service account access to do what ever you like like any other user.

If you want it in calendar.list call Calendarlist.insert from the service account code. You will only need to run it once to insert the calendar in question into the service accounts calendar list.

try running Calendars.get on the calendar it should have access without needing to insert it into calendar.list



来源:https://stackoverflow.com/questions/34944219/get-add-events-to-google-calendar-with-a-service-account

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