如何使用电子表格api java gdata将列表行更新为现有电子表格的工作表?

时间:2013-07-26 11:29:11

标签: java gdata google-spreadsheet-api

使用eclipse gdata java来处理电子表格.... 现在我尝试使用以下代码将listRow上传到工作表,     公共类reftome {   public static void main(String [] args)       抛出AuthenticationException,MalformedURLException,IOException,ServiceException {

SpreadsheetService service =
    new SpreadsheetService("MySpreadsheetIntegration-v3");
service.setUserCredentials("user@gmail.com", "pass");

// Define the URL to request.  This should never change.
URL metafeedUrl = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full");
SpreadsheetFeed feed = service.getFeed(metafeedUrl, SpreadsheetFeed.class);

List<SpreadsheetEntry> spreadsheets = feed.getEntries();

if (spreadsheets.size() == 0) {
  // TODO: There were no spreadsheets, act accordingly.
}

// TODO: Choose a spreadsheet more intelligently based on your
// app's needs.
SpreadsheetEntry entry = null;
for (int i = 0; i < spreadsheets.size(); i++)
{
    entry = spreadsheets.get(i);
    String dum=entry.getTitle().getPlainText();
    if(dum.contains("reference_me"))
        break;
}
SpreadsheetEntry spreadsheet = entry;
System.out.println(spreadsheet.getTitle().getPlainText());

// Get the first worksheet of the first spreadsheet.
// TODO: Choose a worksheet more intelligently based on your
// app's needs.
WorksheetFeed worksheetFeed = service.getFeed(
    spreadsheet.getWorksheetFeedUrl(), WorksheetFeed.class);
List<WorksheetEntry> worksheets = worksheetFeed.getEntries();
WorksheetEntry worksheet = worksheets.get(0);

// Fetch the list feed of the worksheet.
URL listFeedUrl = worksheet.getListFeedUrl();
ListFeed listFeed = service.getFeed(listFeedUrl, ListFeed.class);

// Create a local representation of the new row.
ListEntry row = new ListEntry();
row.getCustomElements().setValueLocal("firstname", "Joe");
row.getCustomElements().setValueLocal("lastname", "Smith");
row.getCustomElements().setValueLocal("age", "26");
row.getCustomElements().setValueLocal("height", "176");

service.insert(listFeedUrl, row);

} }

但是最后一行“service.insert(listFeedUrl,row);”失败并给出以下消息,

Exception in thread "main" com.google.gdata.util.InvalidEntryException: Bad Request

很抱歉,发生了服务器错误。请稍等一下,然后尝试重新加载电子表格。

at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:602)
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.insert(Service.java:1409)
at com.google.gdata.client.GoogleService.insert(GoogleService.java:613)
at reftome.main(reftome.java:61)

任何人都可以帮我解决这个问题....?

0 个答案:

没有答案