1

我正在使用 eclipse gdata java 来处理电子表格......现在我正在尝试借助以下代码将 listRow 上传到工作表,public class refome { public static void main(String[] args) throws AuthenticationException, MalformedURLException, IOException , 服务异常 {

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)

谁能帮我解决这个问题......?

4

0 回答 0