简体   繁体   English

Google Calendar API v3在一个请求中包含多个事件(使用C#服务器API)

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

What I'm trying is to send a batch of calendar events with one request using Google calendar client library for .Net. 我正在尝试的是使用.Net的Google日历客户端库通过一个请求发送一批日历事件。 By the way, it has a very poor documentation and I still have no idea how to implement it. 顺便说一下,它的文档非常差,我仍然不知道如何实现它。 Everything i can do now is: Insert event into the CalendarService.Events object and then Fetch it (one request per event). 我现在所能做的就是:将事件插入CalendarService.Events对象,然后提取它(每个事件一个请求)。 Does this api even provide such functionality for batch requests and if it do, can anyone show examples? 此api是否甚至为批处理请求提供了此类功能,如果这样做,任何人都可以显示示例吗?

Hope this may help you 希望这对您有帮助

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();

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

I agree with you about the terrible documentation, but after a lot of hacking around, I got this to work. 对于可怕的文档,我同意您的看法,但是经过大量的修改之后,我才开始使用它。 I wrote this up here as an answer to another SO question . 在这里写这是对另一个SO问题的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM