Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓:在谷歌电子数据表中添加行_Android_Google Sheets - Fatal编程技术网

Android 安卓:在谷歌电子数据表中添加行

Android 安卓:在谷歌电子数据表中添加行,android,google-sheets,Android,Google Sheets,我使用下面的代码添加一个列表行,它成功了。但它看起来很复杂 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/f

我使用下面的代码添加一个列表行,它成功了。但它看起来很复杂

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);
电子表格服务=
新的电子表格服务(“MySpreadsheetIntegration-v1”);
//定义要请求的URL。这一点永远不会改变。
URL电子表格\u提要\u URL=新URL(
"https://spreadsheets.google.com/feeds/spreadsheets/private/full");
//TODO向API发出请求并获取所有电子表格。
/*
在这里,不是要求所有的电子表格,
我只想申请我存储在谷歌硬盘上的电子表格。
*/
SpreadsheetFeed=service.getFeed(电子表格\u feed\u URL,
电子表格feed.class);
列表电子表格=feed.getEntries();
如果(电子表格.size()==0){
//TODO:没有电子表格,请相应地采取行动。
}
电子表格输入电子表格=电子表格.get(0);
System.out.println(电子表格.getTitle().getPlainText());
//获取第一个电子表格的第一个工作表。
//TODO:根据您的需求更智能地选择工作表
//应用程序的需求。
工作表提要工作表提要=service.getFeed(
电子表格.getWorksheetFeedUrl(),WorksheetFeed.class);
List worksheets=worksheetFeed.getEntries();
WorksheetEntry工作表=worksheets.get(0);
//获取工作表的列表提要。
URL listFeedUrl=工作表。getListFeedUrl();
ListFeed ListFeed=service.getFeed(listFeedUrl,ListFeed.class);
//创建新行的本地表示形式。
ListEntry行=新建ListEntry();
row.getCustomElements().setValueLocal(“firstname”、“Joe”);
row.getCustomElements().setValueLocal(“lastname”、“Smith”);
//将新行发送到API以进行插入。
行=服务.insert(listFeedUrl,行);
现在,我想简单一点

而不是请求所有电子表格, 我只想申请存储在Google Drive上的电子表格。

我有文件电子表格的链接,docs.google.com/spreadsheet/ccc?key=KEYOFFILE#gid=0

请告诉我怎么做, 谢谢,

好的, 我自己修

改用

URL SPREADSHEET_FEED_URL = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full");
我们使用:

URL SPREADSHEET_FEED_URL = new URL("https://spreadsheets.google.com/feeds/worksheets/KEYOFTHEFILE/private/full")

谢谢,

我们可以不使用auth2Yes添加行吗。您需要文件的密钥。