我正在使用python API向我的G Suite域用户推送日历。我希望能够指定日历在用户的Feed中显示的颜色,但日历总是会出现相同的无聊蓝色。
这是添加日历的位置(这可以在日历显示在用户列表中,但忽略颜色)
def google_add_cals_to_user(self, user):
cals = GoogleCalendar.objects.calendars_for_user(user)
cal_client = self.setup_user_cal(user.email)
for cal in cals:
cal_body = {
'selected': True,
'id': cal.address,
'colorRgbFormat': True,
'foregroundColor': '#000000',
'backgroundColor': '#' + cal.colour
}
self.execute(cal_client.calendarList().insert(body=cal_body))
以下是构建日历服务的位置:
def setup_user_cal(self, email):
logger.debug('building calendar service for %s' % email)
http_cal = self.key_auth(email, scopes=SCOPES_CAL)
return self.build_service('calendar', 'v3', http_cal)
和身份验证码:
def key_auth(self, user_email, scopes=SCOPES, http=None):
"""
This sets up auth using a private key set up as per: https://developers.google.com/drive/v2/web/delegation
"""
f = file(settings.GOOGLE_SERVICE_ACCOUNT_PKCS12_FILE_PATH, 'rb')
key = f.read()
f.close()
credentials = SignedJwtAssertionCredentials(settings.GOOGLE_SERVICE_ACCOUNT_EMAIL, key,
scope=scopes, sub=user_email)
if not http:
http = httplib2.Http()
http = credentials.authorize(http)
return http
和build_service:
def build_service(self, serviceName, version, http):
retries = 10
for n in range(1, retries+1):
try:
return build(serviceName, version, http=http)
except AccessTokenRefreshError, e:
...
答案 0 :(得分:0)
Calendars.insert将日历ID和日历正文作为参数
在请求正文中,提供具有以下属性的Calendars resource:
如果您查看日历资源的文档,您将看到
{
"kind": "calendar#calendar",
"etag": etag,
"id": string,
"summary": string,
"description": string,
"location": string,
"timeZone": string
}
如您所见,这些是您可以插入的唯一字段。颜色不在其中。我也检查了calendars.patch,你甚至无法更新日历颜色。
通常情况下,我建议您为其添加功能请求。但是,我无法找到Google日历API的问题论坛。