Google Calendar API V3 android-免费获取全天活动 [英] Google Calendar API V3 android - Get all day events for freeBusyRequest

查看:88
本文介绍了Google Calendar API V3 android-免费获取全天活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Android版google-api-services-calendar:v3(使用Kotlin)获取Google组织内其他人的免费忙碌数据.对于设定持续时间的事件,我的时间很好.但是,全天活动不会显示在列表中.几乎找不到这方面的文档,而我在developers.google.com上发现的东西包含2013年不推荐使用的代码...

I'm trying to get the Free busy data of other people that are within my Google organization using the google-api-services-calendar:v3 for Android (using Kotlin). I'm getting the times just fine for events with a set duration. But all day events don't show up on the list. Documentation on this is almost nowhere to be found and the stuff that I find on developers.google.com contains code that was deprecated in 2013...

// ...
val busyTimesList = mutableListOf<AgendaPlotter.TimeSpan>()
    SessionService.sharedInstance.getGoogleAccount(activity)
        observeOn(Schedulers.io())
        .subscribe {
            mCredential!!.selectedAccount = it.account
            val request = FreeBusyRequest()

            val durationCal = Calendar.getInstance()
            durationCal.time = startDay.time
            Calendars.startOfDay(durationCal)
            request.timeMin = DateTime(durationCal.time)
            durationCal.add(Calendar.DATE, 1)
            request.timeMax = DateTime(durationCal.time)


            val requestItems = listOf(FreeBusyRequestItem().setId("email@from.colleague"))
            request.items = requestItems
            request.timeZone = TimeZone.getDefault().id

            val busyTimes: FreeBusyResponse
               try {
                    val query = mService!!.freebusy().query(request)
                    // Use partial GET to retrieve only needed fields.
                    query.fields = "calendars"
                    busyTimes = query.execute()
                    busyTimes.calendars.forEach {
                    it.toPair().second.busy.forEach { timeSpan ->
                        val busyTime = AgendaPlotter.TimeSpan()
                        busyTime.fromTime.timeInMillis = timeSpan.start.value
                        busyTime.toTime.timeInMillis = timeSpan.end.value
                        busyTimesList.add(busyTime)
                    }
                 }
                 emitter.onNext(busyTimesList)
             } catch (e: IOException) {
                 e.printStackTrace()
                 // ...
             }
         }
// ...

所以我的问题是,我还如何获得全天活动?

So my question, how do I also obtain the whole day events?

推荐答案

经过一番搜索,我发现API实际上没有任何问题.这是一整天都忙于免费活动的设置.

After some searching I noticed that there is actually nothing wrong with the API. It's a setting for a whole day event to be busy of free.

默认情况下将其设置为空闲,这使其不会显示为忙碌时间,这是有道理的.很多人没有注意到这一点,他们将在那天免费".

By default this is set to free, which makes it not show as a busy time, which makes sense. This goes unnoticed by a lot of people and they will be "free" on that day.

这篇关于Google Calendar API V3 android-免费获取全天活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆