如何直接从谷歌电子表格中获取数据? [英] How get data directly from a google spreadsheet?
问题描述
我需要我的android应用程序将ALWAYS连接到同一个Google电子表格以获取单元格数据(我将在每天的将来更改,以便应用程序可以在不使用服务器的情况下获取更新的数据)。
在文档 https://开发人员。 google.com/google-apps/spreadsheets/?hl=it#ListFeeds ,它展示了如何进行身份验证等,但我需要的是使用直接链接连接到公共电子表格:
https://docs.google.com/spreadsheet/ ccc?key = xxx ....
这可能吗?
可能的话,一些例子可以是James Moore的代码 http://blog.restphone.com/2011/05/very-simple-google-spreadsheet-code.html 请记住,您需要在电子表格文件 - >发布到网络中手动添加 I need my android application to connect ALWAYS to the same google spreadsheet to get cells data (that i will change in the future every day so the application can get updated data without use a server). In documentation https://developers.google.com/google-apps/spreadsheets/?hl=it#ListFeeds it's showed how to authenticate etc but what i need would be to connect to a public spreadsheet using the straight link like: https://docs.google.com/spreadsheet/ccc?key=xxx.... Is that possible? Is possible, some example can be the code of James Moore http://blog.restphone.com/2011/05/very-simple-google-spreadsheet-code.html Remember you need to add manually in spreadsheet "File->Publish to the Web"
这篇关于如何直接从谷歌电子表格中获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
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);
尝试{
//注意,url以默认值/ public / values结尾
//。
//对于文档而言,这并不明显(至少对我来说)
//。
String urlString =https://spreadsheets.google.com/feeds/list/0AsaDhyyXNaFSdDJ2VUxtVGVWN1Yza1loU1RPVVUU3OFE/default/public/values;
//将字符串转换为URL
URL url = new URL(urlString);
//你可以用这里的单元格替换
//列表源
ListFeed feed = service.getFeed(url,ListFeed.class); (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();
}
}
}
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();
}
}
}