簡體   English   中英

Google Calendar API v3在一個請求中包含多個事件(使用C#服務器API)

[英]Google Calendar API v3 multiple events in one request (using C# server api)

我正在嘗試的是使用.Net的Google日歷客戶端庫通過一個請求發送一批日歷事件。 順便說一下,它的文檔非常差,我仍然不知道如何實現它。 我現在所能做的就是:將事件插入CalendarService.Events對象,然后提取它(每個事件一個請求)。 此api是否甚至為批處理請求提供了此類功能,如果這樣做,任何人都可以顯示示例嗎?

希望這對您有幫助

UserCredential credential;
using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
{
    credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
        GoogleClientSecrets.Load(stream).Secrets,
        new[] { CalendarService.Scope.Calendar },
        "user", CancellationToken.None, new FileDataStore("Calendar.Sample.Store"));
}

// Create the service.
var service = new CalendarService(new BaseClientService.Initializer()
    {
        HttpClientInitializer = credential,
        ApplicationName = "Google Calendar API Sample",
    });

// Create a batch request.
var request = new BatchRequest(service);
request.Queue<CalendarList>(service.CalendarList.List(),
     (content, error, i, message) =>
     {
         // Put your callback code here.
     });
request.Queue<Event>(service.Events.Insert(
     new Event
     {
         Summary = "Learn how to execute a batch request",
         Start = new EventDateTime() { DateTime = new DateTime(2014, 1, 1, 10, 0, 0) },
         End = new EventDateTime() { DateTime = new DateTime(2014, 1, 1, 12, 0, 0) }
     }, "YOUR_CALENDAR_ID_HERE"),
     (content, error, i, message) =>
     {
         // Put your callback code here.
     });
// You can add more Queue calls here.

// Execute the batch request, which includes the 2 requests above.
await request.ExecuteAsync();

摘自: https : //developers.google.com/api-client-library/dotnet/guide/batch

對於可怕的文檔,我同意您的看法,但是經過大量的修改之后,我才開始使用它。 在這里寫這是對另一個SO問題的答案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM