Official Google Spreadsheet/Drive usage

一曲冷凌霜 提交于 2019-12-12 05:13:37

问题


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.)?


回答1:


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.




回答2:


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)



来源:https://stackoverflow.com/questions/35863845/official-google-spreadsheet-drive-usage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!