如何使用Google Calendar API v3更改日历的颜色?

问题描述:

我有此代码段,这与编辑谷歌日历API V3日历摘要:如何使用Google Calendar API v3更改日历的颜色?

com.google.api.services.calendar.model.Calendar calendar = mService.calendars().get(CalendarActivity.this.editid).execute(); 
calendar.setSummary(CalendarActivity.this.title); 
com.google.api.services.calendar.model.Calendar updatedCalendar = mService.calendars().update(calendar.getId(), calendar).execute(); 

但如何改变日历的颜色?

没有setColorId()方法。不知道该怎么做。

在日历API中,当您使用colorId属性使用Events.insert时,您可以在谈论事件时设置颜色。但是,查看Calendar.insert文档,没有办法设置日历的颜色,仅限于事件。

+0

因此,有没有可能改变日历的颜色? – ubik

您可以使用此一:

import com.google.api.services.calendar.Calendar; 
import com.google.api.services.calendar.model.CalendarListEntry; 

// ... 

// Initialize Calendar service with valid OAuth credentials 
Calendar service = new Calendar.Builder(httpTransport, jsonFactory, credentials) 
    .setApplicationName("applicationName").build(); 

// Retrieve the calendar list entry 
CalendarListEntry calendarListEntry = service.calendarList().get("calendarId").execute(); 

// Make a change 
calendarListEntry.setColorId("0"); 

// Update the altered entry 
CalendarListEntry updatedCalendarListEntry = 
    service.calendarList().update(calendarListEntry.getId(), calendarListEntry).execute(); 

System.out.println(updatedCalendarListEntry.getEtag()); 

https://developers.google.com/google-apps/calendar/v3/reference/calendarList/update