这是我的代码:
SpreadsheetService spreadsheet= new SpreadsheetService("v1");
spreadsheet.setProtocolVersion(SpreadsheetService.Versions.V3);
try {
spreadsheet.setUserCredentials("username", "password");
URL metafeedUrl = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full");
SpreadsheetFeed feed = spreadsheet.getFeed(metafeedUrl, SpreadsheetFeed.class);
List<SpreadsheetEntry> spreadsheets = feed.getEntries();
for (SpreadsheetEntry service : spreadsheets) {
System.out.println(service.getTitle().getPlainText());
}
} catch (AuthenticationException e) {
e.printStackTrace();
}
但它似乎不起作用。它总是在电子表格的构造函数中崩溃。我正在使用这些库:
谁能告诉我可能出现的问题?
答案 0 :(得分:0)
它在Spreadsheet的构造函数中崩溃了吗?不是SpreadsheetService?电子表格的实例在哪里创建?我猜,也许在幕后的某个地方。无论如何,正如一位评论者所说,用logcat检查。如果你完全不知道它崩溃的地方(它应该告诉你,如果你看到出现的文本墙),只要在任何可能的地方抛出logcat。
static final String MESSAGE = "SPREADSHEET TEST MESSAGE:";
SpreadsheetService spreadsheet= new SpreadsheetService("v1");
Log.d(MESSAGE, "spreadsheet was created successfully.");
spreadsheet.setProtocolVersion(SpreadsheetService.Versions.V3);
Log.d(MESSAGE, "setProtocolVersion done successfully.");
try {
spreadsheet.setUserCredentials("username", "password");
Log.d(MESSAGE, "set credentials worked.");
URL metafeedUrl = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full");
Log.d(MESSAGE, "metafeedUrl was created successfully.");
SpreadsheetFeed feed = spreadsheet.getFeed(metafeedUrl, SpreadsheetFeed.class);
Log.d(MESSAGE, "feed was created, too.");
List<SpreadsheetEntry> spreadsheets = feed.getEntries();
Log.d(MESSAGE, "spreadsheets List was created successfully.");
for (SpreadsheetEntry service : spreadsheets) {
System.out.println(service.getTitle().getPlainText());
}
Log.d(MESSAGE, "The for-loop worked.");
} catch (AuthenticationException e) {
e.printStackTrace();
}
它看起来很愚蠢,但你可以删除它工作后的所有消息。我通常只会做这种事情,如果我不知道所有正在发生的事情的名义;它应该产生比仅仅盯着屏幕更多的结果。
无论如何,看看它失败的地方并从那里弄清楚。一旦你得到更好的信息,也许可以提出一个更清晰的问题。