简体   繁体   中英

GET/ADD Events to google calendar with a service account

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM