Python APIを使用してG Suiteドメインユーザーにカレンダーをプッシュします。私はカレンダーがユーザーのフィードに表示される色を指定できるようにしたいが、カレンダーは常に同じ退屈な青色で表示されます。APIとドメインの委任によってユーザーにGoogleカレンダーを追加しても色が設定されない
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 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 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: ...
自分のアカウントでAPIエクスプローラを使用してみましたが、特定の色のカレンダーを挿入できたため、可能性があります。いずれにしても、私はcalendarList.insert – askvictor
を使用しています。既存のcalendar.listにパッチを当ててみましたか?挿入後、https://developers.google.com/google-apps/calendar/v3/reference/calendarList/patch? – DaImTo