更新Google Spreadsheets中的单元格会返回错误“缺少资源版本ID”/“远程服务器返回错误:(400)错误请求。”

我想更新Google Spreadsheets中的单元格值但不幸的是收到错误:

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

谢谢!

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

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

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

为了清楚起见,我们在工作表上运行Update()时设置了WorksheetEntry.Etag,并且在通过SpreadsheetsService.Batch()进行批量更新时我们也设置了CellEntry.Etag。

到目前为止,谷歌的“新”电子表格似乎还可以正常运行。

这种方法的一个优点是任何并发/合并操作都将被放弃 – 基本上你告诉谷歌你的更新必须吹走单元格中的任何其他并发先前值。

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

 If-Match: * 

哪个说改写任何东西。