Official Google Spreadsheet/Drive usage

2019-09-11 02:50发布

The Google SpreadsheetService seems a 'work in progress' with sometimes/suddenly slow answers, random error messages etc. As some people already suggest i'm using the Google Drive API where possible when working with the Spreadsheet API. But i couldn't find decent documentation about the Google Drive/Spreadsheet API mix.

With some debugging and trial/error i created an 'entrypoint' at the level of SpreadsheetEntry:

String lSpreadsheetFileId = pSpreadsheetFile.getId(); 
String lSpreadsheetUrlString = String.format("https://spreadsheets.google.com/feeds/spreadsheets/%s", lSpreadsheetFileId); 
URL lSpreadsheetUrl = new URL(lSpreadsheetUrlString); 
SpreadsheetEntry lSpreadsheetEntry = mSpreadsheetService.getEntry(lSpreadsheetUrl, SpreadsheetEntry.class);

Now i can start with a query on the SpreadsheetService or with a Google Drive File. Both deliver a SpreadsheetEntry. From this point the code is equal for both situations.

This works, but is is my own Google hacking solution which could break with an update on the interface. I saw some posts with more 'official' methods:

urlFactory.getWorksheetFeedUrl(file.getId(), "private", "full"); // (or any other feed url builder). file.getId()

What is the official 'by design' way to use Google Drive files with Google Spreadsheet?

Can i get some real code examples (more than; "just use the feed" etc.)?

2条回答
冷血范
2楼-- · 2019-09-11 03:05

Google Spreadsheet Service is already deprecated. Use Google Apps Script API instead on your implementation on integrating Google Drive and Spreadsheet. Using the Apps Script API, you can almost implement most of the Google Apps integration in your application.

查看更多
放荡不羁爱自由
3楼-- · 2019-09-11 03:11

If you really need a SpreadsheetEntry, you have to sift through the SpreadsheetFeed and look for the key. You can implement a title query to reduce the number of spreadsheets to examine:

    SpreadsheetQuery spreadsheetQuery 
    = new SpreadsheetQuery(urlFactory.getSpreadsheetsFeedUrl());
    spreadsheetQuery.setTitleQuery(spreadsheet);
    SpreadsheetFeed spreadsheetFeed = myService.query(spreadsheetQuery, SpreadsheetFeed.class);

There doesn't seem to be a query for the key. However, there is hardly a functionality that requires a SpreadsheetEntry and cannot be done with Drive API or lower level feeds (Worksheed, List, or CellFeed)

查看更多
登录 后发表回答