0
我使用下面的代碼爲添加一個列表行,它成功了。但它看起來很複雜。Android:將行添加到Google Spread Sheet中
SpreadsheetService service =
new SpreadsheetService("MySpreadsheetIntegration-v1");
// Define the URL to request. This should never change.
URL SPREADSHEET_FEED_URL = new URL(
"https://spreadsheets.google.com/feeds/spreadsheets/private/full");
// TODO Make a request to the API and get all spreadsheets.
/*
In Here, Instead of request all spread sheets,
I want to request only my spread sheet which I have stored on Google Drive.
*/
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.
}
SpreadsheetEntry spreadsheet = spreadsheets.get(0);
System.out.println(spreadsheet.getTitle().getPlainText());
// Get the first worksheet of the first spreadsheet.
// TODO: Choose a worksheet more intelligently based on your
// app's needs.
WorksheetFeed worksheetFeed = service.getFeed(
spreadsheet.getWorksheetFeedUrl(), WorksheetFeed.class);
List<WorksheetEntry> worksheets = worksheetFeed.getEntries();
WorksheetEntry worksheet = worksheets.get(0);
// Fetch the list feed of the worksheet.
URL listFeedUrl = worksheet.getListFeedUrl();
ListFeed listFeed = service.getFeed(listFeedUrl, ListFeed.class);
// Create a local representation of the new row.
ListEntry row = new ListEntry();
row.getCustomElements().setValueLocal("firstname", "Joe");
row.getCustomElements().setValueLocal("lastname", "Smith");
// Send the new row to the API for insertion.
row = service.insert(listFeedUrl, row);
現在,我想變得簡單。
而不是請求所有電子表格, 我只想要求我存儲在Google雲端硬盤上的電子表格。
我有文件電子表格docs.google.com/spreadsheet/ccc?key= KEYOFFILE#gid = 0的鏈接。
請告訴我如何, 謝謝,
我們可以添加行不auth2 – wadali
是。你需要文件的密鑰。 –