gpt4 book ai didi

android - 如何直接从谷歌电子表格中获取数据?

转载 作者:太空狗 更新时间:2023-10-29 12:48:58 24 4
gpt4 key购买 nike

我需要我的 android 应用程序始终连接到同一个谷歌电子表格以获取单元格数据(我将在未来每天更改,以便应用程序可以在不使用服务器的情况下获取更新的数据)。

在文档中 https://developers.google.com/google-apps/spreadsheets/?hl=it#ListFeeds它展示了如何进行身份验证等,但我需要的是使用直接链接连接到公共(public)电子表格,例如:

https://docs.google.com/spreadsheet/ccc?key=xxx ....

这可能吗?

最佳答案

有可能,一些例子可以是 James Moore 的代码 http://blog.restphone.com/2011/05/very-simple-google-spreadsheet-code.html

请记住,您需要在电子表格“文件->发布到网络”中手动添加

package com.banshee;

import java.io.IOException;
import java.net.URL;

import com.google.gdata.client.spreadsheet.SpreadsheetService;
import com.google.gdata.data.spreadsheet.CustomElementCollection;
import com.google.gdata.data.spreadsheet.ListEntry;
import com.google.gdata.data.spreadsheet.ListFeed;
import com.google.gdata.util.ServiceException;

public class SpreadsheetSucker {
public static void main(String[] args) {
SpreadsheetService service = new SpreadsheetService("com.banshee");
try {
// Notice that the url ends
// with default/public/values.
// That wasn't obvious (at least to me)
// from the documentation.
String urlString = "https://spreadsheets.google.com/feeds/list/0AsaDhyyXNaFSdDJ2VUxtVGVWN1Yza1loU1RPVVU3OFE/default/public/values";

// turn the string into a URL
URL url = new URL(urlString);

// You could substitute a cell feed here in place of
// the list feed
ListFeed feed = service.getFeed(url, ListFeed.class);

for (ListEntry entry : feed.getEntries()) {
CustomElementCollection elements = entry.getCustomElements();
String name = elements.getValue("name");
System.out.println(name);
String number = elements.getValue("Number");
System.out.println(number);
}
} catch (IOException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
}

}
}

关于android - 如何直接从谷歌电子表格中获取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14642932/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com