I use google drive api to export files from drive.google.com:
compile 'com.google.apis:google-api-services-drive:v2-rev201-1.21.0'
The way it's used:
Map<String, String> exportLinks = gFile.getExportLinks();
String exportLink =
exportLinks.get("application/x-vnd.oasis.opendocument.spreadsheet");
I'd like to download spreadsheets as csv instead of ods, but if I use
String exportLink = exportLinks.get("text/csv");
It downloads only the first sheet. I could specify sheet if I knew its' gids. How can I get links for all the pages?
So I decided to use Google Sheets and that's what helped:
compile (group: 'com.google.apis', name: 'google-api-services-sheets', version: 'v4-rev25-1.22.0')
compile (group: 'com.google.gdata', name: 'core', version: '1.47.1')
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
httpTransport, jsonFactory, clientSecrets,
Arrays.asList(DriveScopes.DRIVE, SheetsScopes.SPREADSHEETS_READONLY))
.setDataStoreFactory(dataStoreFactory)
.setAccessType("offline")
.build();
Credential credential = flow.loadCredential(userId);
Sheets sheets = new Sheets.Builder(httpTransport, jsonFactory, credential)
.setApplicationName(APPLICATION_NAME)
.build();
List<Sheets> sheetsList = sheets.spreadsheets().get("mySpreadsheetId").execute().getSheets();
for (Sheet sh : sheetList) {
sout(sh.getProperties().getSheetId());
}
And the properties contain sheets gids.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.