0

我一直在使用新的谷歌日历 V3 API,我已经编写了我所有的类方法来处理添加、更新、检索等,但我想知道是否有办法发送一批添加 + 更新 + 删除全部在一次,而不是单独发送每个请求,并且可能超过 trans/sec 阈值。我了解 .Batch 方法在 V3 中已被贬值,我发现另一种使用 Web 服务的方法会通知客户端更改已准备好,但我正在尝试从 .NET Winform 应用程序执行此操作,因此它需要启动来自客户,不依赖于在线服务或 PUSH 方法。

问候,

克里

4

1 回答 1

3

我让这个使用BatchRequest对象工作:

    Dim initializer As New BaseClientService.Initializer()
    initializer.HttpClientInitializer = credential
    initializer.ApplicationName = "My App"

    Dim service = New CalendarService(initializer)

    'fetch the calendars
    Dim list = service.CalendarList.List().Execute().Items()
    'get the calendar you want to work with
    Dim calendar = list.First(Function(x) x.Summary = "{Calendar Name}")

    Dim br As New Google.Apis.Requests.BatchRequest(service)

    'make 5 events
    For i = 1 To 5
        'create a new event
        Dim e As New [Event]

        'set the event properties
        e.Summary = "Test Event"
        e.Description = "Test Description"
        e.Location = "Test Location"
        ...
        'make a request to insert the event
        Dim ins As New InsertRequest(service, e, calendar.Id)
        'queue the request
        br.Queue(Of Dummy)(ins, AddressOf OnResponse)
    Next

    'execute the batch request
    Dim t = br.ExecuteAsync()
    'wait for completion
    t.Wait()

出于某种原因,如果不指定对方法的回调,就不能有延迟请求Queue,并且该方法需要泛型类型参数。所以我定义了以下内容:

Class Dummy
End Class

Sub OnResponse(content As Dummy, err As Google.Apis.Requests.RequestError, index As Integer, message As System.Net.Http.HttpResponseMessage)
End Sub

有了这个,批量插入工作正常。

于 2014-01-31T00:42:45.560 回答