如何将 Android 应用程序与 Google Sheets 电子表格连接起来? [英] How do I connect Android apps with Google Sheets spreadsheets?
问题描述
我正在尝试开发一个需要与 Google 电子表格 API 配合使用的 Android 应用.我是新手,所以我从 api 的第 3 版开始:https://developers.google.com/google-apps/spreadsheets/
I'm trying to do an Android app that needs to work with Google spreadsheet API. I'm new in this, so I'm starting with the version 3 of the api: https://developers.google.com/google-apps/spreadsheets/
我按照所有步骤,将所有 jar 文件下载到我的项目文件夹中的 lib
子文件夹,然后像往常一样添加到 Eclipse 中的构建路径.所以虽然没有Java示例来执行Oauth 2.0,我只是尝试声明:
I followed all the steps, downloaded all the jar files to lib
subfolder in my project folder and then I added to the build path in Eclipse as usual. So although there is no Java example to perform Oauth 2.0, I just tried to declare:
SpreadsheetService service = new SpreadsheetService("v1");
但是当我模拟这个简单的行时,它给了我一个错误:
but when I emulate this simple line it gives me an error:
java.lang.NoClassDefFoundError: com.google.gdata.client.spreadsheet.SpreadsheetService
我正在使用文档中包含的所有 jars 并且我有导入:
I'm using all the jars included in the documentation and I have the import:
import com.google.gdata.client.spreadsheet.SpreadsheetService;
但我完全迷失了.我不知道还能做些什么来开始、连接到 Google API 并使用电子表格.
but I am totally lost. I dont know what else to do just to start, connect to Google APIs and work with the spreadsheets.
推荐答案
非常感谢 Scorpion!有用!!我已经尝试这个太久了.好的,这是我的解决方案:我开始了一个新项目并包含了这些 jars:
Thank you so so much Scorpion! It works!! I've been trying this for too long. Ok here is my solution: I started a new project and included these jars:
gdata-client-1.0
gdata-client-meta-1.0
gdata-core-1.0
gdata-spreadsheet-3.0
gdata-spreadsheet-meta-3.0
guava-13.0.1
和我的代码:
SpreadsheetService spreadsheet= new SpreadsheetService("v1");
spreadsheet.setProtocolVersion(SpreadsheetService.Versions.V3);
try {
spreadsheet.setUserCredentials("username", "password");
URL metafeedUrl = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full");
SpreadsheetFeed feed = spreadsheet.getFeed(metafeedUrl, SpreadsheetFeed.class);
List<SpreadsheetEntry> spreadsheets = feed.getEntries();
for (SpreadsheetEntry service : spreadsheets) {
System.out.println(service.getTitle().getPlainText());
}
} catch (AuthenticationException e) {
e.printStackTrace();
}
当然这是在不同的线程中执行的,而不是在主线程中.没有 OAuth 2.0 的 Java 文档,但我会尝试,如果我做不到,我会在这里问.再次,非常感谢你,我希望在我这次工作足够的时候帮助你.:)
of course this is executed in a different thread not in the main thread. There is no java documentation for OAuth 2.0 but I will try and if I can't do it I'll ask here. Again, thank you very much and I hope to help you when I work on this time enough. :)
这篇关于如何将 Android 应用程序与 Google Sheets 电子表格连接起来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!