【问题标题】:Updating cell in Google Spreadsheets returns error "Missing resource version ID" / "The remote server returned an error: (400) Bad Request."更新 Google 电子表格中的单元格返回错误“缺少资源版本 ID”/“远程服务器返回错误:(400) 错误请求。”
【发布时间】:2014-03-28 17:10:44
【问题描述】:

我想更新 Google 电子表格中的单元格值,但很遗憾收到错误消息:

Google.GData.Client.GDataRequestException was unhandled
  HResult=-2146233088
  Message=Execution of request failed: https://spreadsheets.google.com/feeds/cells/1nW8nxoS2l9pbj6dctreEfKHNXmsfbbsCAvOd7TIj4Bo/od6/private/full/R1C1
  Source=Google.GData.Client
  ResponseString=Missing resource version ID
  StackTrace:
   at Google.GData.Client.GDataRequest.Execute()
   ...
   at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Net.WebException
   HResult=-2146233079
   Message=The remote server returned an error: (400) Bad Request.
   Source=System
   StackTrace:
        at System.Net.HttpWebRequest.GetResponse()
        at Google.GData.Client.GDataRequest.Execute()

我的代码非常简单,基于从https://developers.google.com/google-apps/spreadsheets/?csw=1#changing_contents_of_a_cell下载的示例:

        SpreadsheetsService service = new SpreadsheetsService("MySpreadsheetIntegration-v1");

        // TODO: Authorize the service object for a specific user (see other sections)
        service.setUserCredentials("...", "...");            

        // Instantiate a SpreadsheetQuery object to retrieve spreadsheets.
        SpreadsheetQuery query = new SpreadsheetQuery();

        // Make a request to the API and get all spreadsheets.
        SpreadsheetFeed feed = service.Query(query);

        foreach (SpreadsheetEntry spreadsheet in feed.Entries)
        {
            if (spreadsheet.Title.Text == "Test01")
            {
                // Get the first worksheet of the first spreadsheet.
                WorksheetFeed wsFeed = spreadsheet.Worksheets;
                WorksheetEntry worksheet = (WorksheetEntry)wsFeed.Entries[0];

                // Fetch the cell feed of the worksheet.
                CellQuery cellQuery = new CellQuery(worksheet.CellFeedLink);
                cellQuery.MinimumRow = 1;
                cellQuery.MaximumRow = 10;
                cellQuery.MinimumColumn = cellQuery.MaximumColumn = 1;
                cellQuery.ReturnEmpty = ReturnEmptyCells.yes;
                CellFeed cellFeed = service.Query(cellQuery);

                // Iterate through each cell, updating its value if necessary.
                foreach (CellEntry cell in cellFeed.Entries)
                {
                    cell.InputValue = "Foooooo!";
                    cell.Update();
                }

            }
        }

以下行引发了错误:

                    cell.Update();

我使用 Google.GData 版本 2.2.0.0 (http://code.google.com/p/google-gdata/)。 你知道什么可能导致这个问题吗?

[编辑] gdata python 客户端也报告了这个问题。希望它很快得到修复。 http://code.google.com/p/gdata-python-client/issues/detail?id=692&sort=-opened&colspec=Opened%20Stars%20ID%20Type%20Status%20Priority%20Component%20Summary

谢谢!

【问题讨论】:

  • 我遇到了这个错误。只是添加它的一个案例。它曾经是可选的,但现在不再是。
  • “添加”到底是什么意思?
  • 抱歉有点匆忙。看起来你有我想要的 ID,即 SpreadsheetsService("MySpreadsheetIntegration-v1"); ....您是否使用旧式电子表格(400,000 个单元格限制)。最后我读到,它不适用于新样式的电子表格,正在进行中。 ....我也使用批量更新,因为使用单个单元格更新很慢。
  • 更新:截至 4 月 1 日,所有 gdata 写入停止工作。如此处所述,我收到“来自您的计算机网络的异常流量”,但读取工作正常。 support.google.com/websearch/answer/86640
  • 我正在使用新的电子表格。它在旧电子表格中运行良好。我认为“异常流量”是另一个与此无关的问题。

标签: c# google-sheets google-spreadsheet-api google-data-api


【解决方案1】:

大约一周前,当 Google 似乎将所有电子表格都转换为“新”格式时,我们遇到了同样的问题。
这也适用于通过 GData api 创建的新的。到处都是 400 错误。

我深入研究了 GData 变体库(Python、Java、.Net 等)的报告,最终发现了这个小块: https://stackoverflow.com/a/23438381/1685090

将 Etag 属性设置为“*”就是答案:)

明确地说,当我们想在工作表上运行 Update() 时,我们设置了 WorksheetEntry.Etag,并且在通过 SpreadsheetsService.Batch() 进行批量更新时,我们还设置了 CellEntry.Etag。

到目前为止,它似乎可以很好地与 Google 的“新”电子表格配合使用。

这种方法的一个问题是任何并发/合并操作都将被放弃 - 本质上,您是在告诉 Google 您的更新必须消除单元格中的任何其他并发先前值。

【讨论】:

  • @Paul DB,您能否插入一个简短的脚本,在 PHP/Zend 中设置该 Etag 属性?我真的很感激!谢谢!
  • 我不确定它在 PHP 中是如何工作的,在 .Net 版本中我相信 ETag 属性映射到一个 'If-Match': '*' 标头被添加到 HTTP 请求中通过网络连接到 Google。
  • 我在我正在编写的一个 python 库上工作 (sheetsync.readthedocs.org/en/latest) 我写了这个猴子补丁 gist.github.com/mbrenig/3d007fb8f5f98468a228 也许你可以做类似的事情?
  • 有没有人找到在 PHP 中做到这一点的方法?希望修复我的电子表格软件,它不能再导入数据...
  • @Laci 你找到解决办法了吗?
【解决方案2】:

我解决此问题的另一种方法是添加额外的 HTTP 标头

If-Match: *

上面写着覆盖任何东西。

【讨论】:

    猜你喜欢
    • 2018-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多