1

这是我的代码:

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();
    }

但这似乎不起作用。它总是在电子表格的构造函数中崩溃。我正在使用这些库:

  • gdata-client-1.0
  • gdata-client-meta-1.0
  • gdata-core-1.0
  • gdata-电子表格-3.0
  • gdata-电子表格-meta-3.0
  • 番石榴-13.0.1

谁能告诉我可能出了什么问题?

4

1 回答 1

0

它在电子表格的构造函数中崩溃?不是电子表格服务?电子表格的实例在哪里创建?也许在幕后的某个地方,我猜。无论如何,正如一位评论者所说,请检查 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();
}

它看起来很愚蠢,但是一旦它起作用,您就可以删除所有消息。我通常只会在我不知道所有神圣事物的名义发生了什么的情况下才会做这种事情;它应该比仅仅盯着屏幕产生更多的结果。

无论如何,看看它失败的地方并从那里弄清楚。一旦你得到更好的信息,也许会问一个更清楚的问题。

于 2013-07-10T21:53:07.957 回答