【问题标题】:com.google.gdata.util.PreconditionFailedException on ListEntry.update() in Google Docs Java APIGoogle Docs Java API 中 ListEntry.update() 上的 com.google.gdata.util.PreconditionFailedException
【发布时间】:2013-09-25 13:53:46
【问题描述】:

我有一个应用程序可以操作谷歌电子表格的行。有时,当我调用 ListEntry.update() 时,我会收到以下堆栈跟踪:

Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: com.google.gdata.util.PreconditionFailedException: Precondition Failed
Mismatch: etags = ["E10QemAgYit7ImA-CEFaShYM"], version = [2ag9hk74om621l]
at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:614)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:564)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:560)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:538)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:536)
at com.google.gdata.client.Service.update(Service.java:1563)
at com.google.gdata.client.Service.update(Service.java:1530)
at com.google.gdata.client.GoogleService.update(GoogleService.java:597)
at com.google.gdata.data.BaseEntry.update(BaseEntry.java:639)
at feedProcessor.ProcessClientFeed.UpdateRow(ProcessClientFeed.java:466)
at feedProcessor.ProcessClientFeed.updateGoogleSpreadsheet(ProcessClientFeed.java:404)
at feedProcessor.ProcessClientFeed.processFeed(ProcessClientFeed.java:318)
at feedProcessor.ProcessClientFeed.main(ProcessClientFeed.java:61)
... 5 more

【问题讨论】:

    标签: java google-api


    【解决方案1】:

    以下是相关文档:

    https://developers.google.com/gdata/javadoc/com/google/gdata/data/spreadsheet/ListEntry

    https://developers.google.com/gdata/javadoc/com/google/gdata/data/BaseEntry#update()

    根据这些文档,update() 函数甚至无法抛出 PreconditionFailedException,因此这些文档在这里基本上是无用的。测试该问题表明,当您在会话中多次尝试在同一行上调用 update() 函数时,会引发此异常。究竟是什么定义了“会话”仍不清楚,但如果您不止一次地遍历所有行,并在每次迭代中对每一行调用 update(),您将收到此错误。我知道的唯一解决方案是编写您的软件,使每一行 (ListEntry) 的 update() 仅调用一次。

    【讨论】:

      【解决方案2】:

      问题是由 Google 电子表格 API Resource Versioning mecanism 引起的。

      为了能够编辑条目无论如何 - 只需使用:

      entry.setEtag("*")
      

      更新前。

      是的,这不是多用户友好的。如果您需要多用户支持,请重新获取 Feed。

      【讨论】:

        猜你喜欢
        • 2012-05-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多