【发布时间】:2016-04-20 11:41:58
【问题描述】:
tutorial 中提供的代码(下面给出了 sn-p)检索经过身份验证的用户的所有电子表格的列表。
public class MySpreadsheetIntegration {
public static void main(String[] args) throws AuthenticationException,
MalformedURLException, IOException, ServiceException {
SpreadsheetService service = new SpreadsheetService("MySpreadsheetIntegration-v1");
// 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();
// Iterate through all of the spreadsheets returned
for (SpreadsheetEntry spreadsheet : spreadsheets) {
// Print the title of this spreadsheet to the screen
System.out.println(spreadsheet.getTitle().getPlainText());
}
}
}
但我不想获取所有电子表格。我只想获取特定文件夹中的那些电子表格(如果该文件夹存在,否则终止程序)。是否可以使用此 API?如果是,怎么做?
据我了解,SpreadsheetFeed 必须更改。但我没有得到任何反对它的例子。
【问题讨论】:
-
我认为电子表格 API 甚至没有“文件夹”的概念。您需要来自 Drive API 的 children.list。这将返回文件列表,而不是电子表格;但是 URL 包含电子表格 ID,因此您可以尝试通过这种方式访问它们……或者只使用 Apps Script API,它提供了一种将 File 对象传递给 SpreadsheetApp 的简洁方法,返回电子表格。
-
@Meta 好的,我明白了。但我必须先得到文件夹。另外,我可以从 fileId 获取 SpreadsheetEntry 吗?
标签: java google-sheets google-sheets-api