【发布时间】:2012-09-11 05:32:10
【问题描述】:
我的 Google Drive 中有一个电子表格文件,我想从 Android 应用程序同步它。成功同步后,我的应用程序中有一些搜索条件,我希望从我同步的文件中获得基于此条件的结果。我是第一次这样做,并没有获得好的资源。
1) 如何在 Android App 中同步 Google Drive 文件?
2) 如何从我已同步的电子表格中检索特定数据?
注意 - 我也对 Google Docs API 和 Google Drive SDK 感到困惑。
在我的应用程序中使用什么?
我每次只有一个文件要同步,而不是所有文件。并且该文件通过私钥对所有人开放。
我已经实现了一些代码,但它不起作用。下面是我想在我的 Android 应用中同步的电子表格公共网址。
我正在按照here 的步骤进行操作。
try {
String USERNAME = "xxxxx";
String PASSWORD = "xxxxx";
SpreadsheetService service =
new SpreadsheetService("Testing");
service.setUserCredentials(USERNAME, PASSWORD);
// TODO: Authorize the service object for a specific user (see other sections)
// Define the URL to request. This should never change.
URL SPREADSHEET_FEED_URL = new URL(
"https://spreadsheets.google.com/feeds/spreadsheets/private/full");
// Make a request to the API and get all spreadsheets.
SpreadsheetFeed feed = service.getFeed(SPREADSHEET_FEED_URL,
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 spreadsheet = spreadsheets.get(0);
System.out.println(spreadsheet.getTitle().getPlainText());
// Make a request to the API to fetch information about all
// worksheets in the spreadsheet.
List<WorksheetEntry> worksheets = spreadsheet.getWorksheets();
// Iterate through each worksheet in the spreadsheet.
for (WorksheetEntry worksheet : worksheets) {
// Get the worksheet's title, row count, and column count.
String title = worksheet.getTitle().getPlainText();
int rowCount = worksheet.getRowCount();
int colCount = worksheet.getColCount();
// Print the fetched information to the screen for this worksheet.
System.out.println("\t" + title + "- rows:" + rowCount + " cols: " + colCount);
}
} catch (Exception e) {
e.printStackTrace();
}
【问题讨论】:
-
如果有人有任何想法,请帮助我。我正在寻找建议...
-
您是如何在 Android 应用中同步 Google Drive 文件的?
标签: android google-docs google-sheets google-spreadsheet-api