【问题标题】:Invalid Resource Id when batch inserting批量插入时资源 ID 无效
【发布时间】:2014-05-20 23:46:21
【问题描述】:

我正在使用 .NET API 批量插入 Google 日历。我有以下代码。

var request = new BatchRequest(calendarService);

request.Queue<Event>(
    calendarService.Events.Insert(
    new Event
    {                            
        Id = String.Format("yot-{0}", item.AppointmentId),
        Summary = item.Title,
        Description = item.Description,
        Start = new EventDateTime() { DateTime = item.Date },
        End = new EventDateTime() { DateTime = item.Date.AddHours(item.Length) }
    }, calendar.Id),
    (content, error, i, message) =>
    {
        //Log error
    });

request.ExecuteAsync(); 

当我执行并尝试插入时,我收到错误“资源 ID 无效”。这个错误是什么意思?

【问题讨论】:

  • 您是否尝试在不使用批处理的情况下运行相同的请求?
  • 没有批处理也不起作用。如果我停止尝试设置 Id,它确实有效,但据此我应该设置 Id。 developers.google.com/admin-sdk/calendar-resource
  • 您是否遵循这些规则:事件的标识符。在创建新的单个或重复事件时,您可以指定它们的 ID。提供的 ID 必须遵循以下规则: ID 中允许的字符是 base32hex 编码中使用的字符,即小写字母 a-v 和数字 0-9,请参阅 RFC2938 中的第 3.1.2 节 ID 的长度必须在 5 到 1024 个字符之间 ID每个日历必须是唯一的。看看developers.google.com/google-apps/calendar/v3/reference/events/…

标签: google-api google-api-dotnet-client


【解决方案1】:

您必须遵循此处定义的准则:https://developers.google.com/google-apps/calendar/v3/reference/events/insert

基本上,id 的长度必须在 5 到 1024 个字符之间,并且仅由以下字母中的字符组成:0123456789abcdefghijklmnopqrstuv。

如果您不想要随机 ID,请尝试使用简单的 Guid.NewGuid() 或 use a Base32 Encoder

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-19
  • 1970-01-01
  • 2016-03-22
相关资源
最近更新 更多