如何在网络中使用TimeMax和TimeMin获取一天的事件(Google日历Api)?

时间:2014-09-30 00:24:57

标签: vb.net google-calendar-api

我有一个代码,用于获取日历的事件列表,但检索所有事件。我怎样才能获得一天的活动?

以下是我使用的代码:

Imports Google.Apis.Auth.OAuth2
Imports Google.Apis.Services
Imports System.Collections.Generic
Imports Google.Apis.Calendar.v3
Imports Google.Apis.Calendar.v3.Data
Imports Google.Apis.Calendar.v3.Data.Event
Imports Google.Apis.Util.Store
Imports Google.Apis.Calendar.v3.EventsResource
Imports System.Threading
Public Class Form1
    Dim scopes As IList(Of String) = New List(Of String)
    Dim service As CalendarService
    Dim initializer = New BaseClientService.Initializer
    Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
        Dim service As CalendarService
        Try
            scopes.Add(CalendarService.Scope.Calendar)
            Dim Secrets = New ClientSecrets()
            Secrets.ClientId = "CLIENT ID"
            Secrets.ClientSecret = "CLIENT SECRET"
            Dim scope = New List(Of String)
            scope.Add(CalendarService.Scope.Calendar)
            Dim credential = GoogleWebAuthorizationBroker.AuthorizeAsync(Secrets, scopes, "xxxxxxxxxxx@developer.gserviceaccount.com", CancellationToken.None).Result()
            Dim initializer = New BaseClientService.Initializer
            initializer.HttpClientInitializer = credential
            initializer.ApplicationName = "APP NAME"
            service = New CalendarService(initializer)
            Dim list As IList(Of CalendarListEntry) = service.CalendarList.List().Execute().Items
            Dim requeust As ListRequest = service.Events.List("MY EMAIL")
            Me.DataGridView1.DataSource = requeust.Execute.Items
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
End Class

1 个答案:

答案 0 :(得分:0)

尝试使用以下几行代码添加搜索范围

requeust.TimeMax = Now.ToString("yyyy-MM-dd'T'HH:mm:ss.fffK")
requeust.TimeMin = "2014-12-01T16:00:00"   'changing the time whenever you want

我认为它的工作:)