本文介绍了使用Google Calendar V3 API进行批处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用新的Google Calendar V3 API,并且已经编写了所有类方法来处理添加,更新,检索等操作,但是我想知道是否有一种方法可以发送一批添加+更新+一次删除所有内容,而不是分别发送每个请求,并且可能超出传输/秒阈值.我知道.Batch方法在V3中已被贬值,我发现了另一种使用Web服务的方法,该方法将通知客户端更改已准备就绪,但是我正在尝试通过.NET Winform应用程序执行此操作,因此需要将其启动来自客户,而不依赖在线服务或PUSH方法.

I've been working with the new google Calendar V3 API and I've coded all my class methods to process Adds, Updates, retrievals etc but I was wondering if there is a way to send a batch of adds + updates + deletes all at once rather than sending each request separately and possible exceeding the trans/sec threshold. I understand the .Batch method has been depreciated in V3 and I found another methodology that uses web services that will notify a client that changes are ready but I'm trying to do this from a .NET Winform application so it needs to be something initiated from the client and not dependent upon online services or a PUSH methodology.

此致

克里

推荐答案

我使用BatchRequest对象使它起作用:

I got this to work using the BatchRequest object:

    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方法的回调,就不能有延迟的请求,并且该方法需要一个泛型类型参数.因此,我定义了以下内容:

For some reason, you can't have a deferred request without specifying a callback to the Queue method, and that method requires a generic type parameter. So I defined the following:

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

有了这个,批处理插件就可以正常工作了.

With this in place, the batch inserts worked fine.

这篇关于使用Google Calendar V3 API进行批处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 01:08
查看更多