Http 谷歌日历API-只能更新事件一次

Http 谷歌日历API-只能更新事件一次,http,curl,http-headers,google-api,google-calendar-api,Http,Curl,Http Headers,Google Api,Google Calendar Api,我遇到了与本文所述相同的问题: 也就是说,一旦我创建了一个事件并使用Google日历API(v3)更新了它,我就不能再更新该事件了。当我尝试执行此操作时,会得到一个400无效值的响应。(FWIW我在PHP工作) 根据我在上面提到的文章中提供的线索,我尝试使用ETag解决这个问题(尽管我对它们如何工作的理解是有限的)。基本上,在事件更新时,API在其响应中返回一个etag,我现在将其保存在数据库中。然后,对于后续(n>1)更新,我从数据库中提取当前etag并将其包含在http头中: Conten

我遇到了与本文所述相同的问题:

也就是说,一旦我创建了一个事件并使用Google日历API(v3)更新了它,我就不能再更新该事件了。当我尝试执行此操作时,会得到一个400无效值的响应。(FWIW我在PHP工作)

根据我在上面提到的文章中提供的线索,我尝试使用ETag解决这个问题(尽管我对它们如何工作的理解是有限的)。基本上,在事件更新时,API在其响应中返回一个etag,我现在将其保存在数据库中。然后,对于后续(n>1)更新,我从数据库中提取当前etag并将其包含在http头中:

Content-Type:  application/json
Authorization:  OAuth [token]
If-Match: [etag]
以下是“更新条目”标题下的信息:

旁注:在上面的谷歌参考中,If匹配头显示为

If-Match: "S0wCTlpIIip7ImA0X0QI"
在etag周围加上双引号。我用双引号将ETag保存在数据库中,就像我在第一次更新响应中收到它们一样。使用curl_setopt/HTTPHEADER添加到标头时,是否需要转义引号或其他内容

尽管实现了这个etag If Match,我仍然得到了相同的400无效值响应。我知道我的请求主体是有效的,因为第一次更新工作正常。在后续更新方面还有一些额外的问题


非常感谢您的帮助。

请确保在更新事件时增加序号字段。

我也遇到了同样的问题。要增加序列号,您需要跟踪已完成的更新数量,并在更新中包含下一个增量。出于某种原因,第一次更新不需要此功能,但后续更新确实需要此功能

在事件的第二次更新中使用google php库看起来像这样(减去正在更新的其他内容):


我就是这样做的。从Google获取条目,这样它就已经有了最新的Etag集,并将序列增加1,然后更新条目

由于我使用java,下面是一个java示例:

com.google.api.services.calendar.model.Event googleCalendarEvent = service.events().get(clientCalendarEvent.getCalendar().getCalendarKey(),clientCalendarEvent.getEventKey()).execute();
updateGoogleCalendarEvent(clientCalendarEvent, googleCalendarEvent);

googleCalendarEvent.setSequence(googleCalendarEvent.getSequence() + 1);

com.google.api.services.calendar.model.Event event = service
      .events()
      .update(clientCalendarEvent.getCalendar().getCalendarKey(), clientCalendarEvent.getEventKey(),
          googleCalendarEvent).execute();

您是否遵循“要使用If Match更新条目,请从获取您正在更新的条目开始。对条目进行任何所需的更改,然后创建一个包含已修改条目的新PUT请求”的说明。感谢您的后续操作。我刚刚实现了一个“更新”,删除了现有事件并创建了一个新事件。是的,您应该增加序列号并将其与更新请求一起发送。Google真的应该在文档中提到,后续更新需要此字段
com.google.api.services.calendar.model.Event googleCalendarEvent = service.events().get(clientCalendarEvent.getCalendar().getCalendarKey(),clientCalendarEvent.getEventKey()).execute();
updateGoogleCalendarEvent(clientCalendarEvent, googleCalendarEvent);

googleCalendarEvent.setSequence(googleCalendarEvent.getSequence() + 1);

com.google.api.services.calendar.model.Event event = service
      .events()
      .update(clientCalendarEvent.getCalendar().getCalendarKey(), clientCalendarEvent.getEventKey(),
          googleCalendarEvent).execute();