在 Android 上使用 GData API 的最佳选择?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/524257/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Best option for using the GData APIs on Android?
提问by nyenyec
What's the least painful and most size efficient way to use the Google Data APIs in an Android application?
在 Android 应用程序中使用 Google 数据 API 的最不痛苦和最有效的方法是什么?
After a few quick searches t seems that there is an android-gdataproject on Google Code that seems to be the work of a single author. I didn't find any documentation for it and don't even know if it's production ready yet.
经过几次快速搜索后,似乎 Google Code 上有一个android-gdata项目,似乎是一个作者的作品。我没有找到它的任何文档,甚至不知道它是否已经准备好生产。
An older option, the com.google.wireless.gdata package seems to have been removedfrom the SDK. It's still availablein the GIT repository.
较旧的选项 com.google.wireless.gdata 包似乎已从SDK 中删除。它仍然在 GIT 存储库中可用。
Before I invest too much time with either approach I'd like to know which is the best supported and least painful.
在我为这两种方法投入太多时间之前,我想知道哪种方法得到最好的支持和最少的痛苦。
回答by Yaniv Inbar
Please take a look at the Google API Client Libraryfor Java which supports Android
请查看支持 Android的Google API Client Libraryfor Java
It also supports new GDatatechnologies like the recently announced partial response/update and JSON-C, both of which can be a dramatic improvement in efficiency on Android.
它还支持新的GData技术,如最近宣布的部分响应/更新和JSON-C,这两种技术都可以显着提高 Android 上的效率。
To start, please take a look at the Android Developer's Guide. Also, please look at the Android sample for Picasa Web Albums Data API, which demonstrates the ability create/update/delete a photo album and to upload a picture.
首先,请查看Android 开发人员指南。另外,请查看Picasa 网络相册数据 API的Android 示例,它演示了创建/更新/删除相册和上传图片的能力。
Full disclosure: I am an owner of the google-api-java-clientproject.
完全披露:我是google-api-java-client项目的所有者。
回答by James A Wilson
I also looked at the google-code project and the git repo. I steered away from the google-code project due to the apparent baggage that came along in required projects. I ended up creating custom implementations as necessary to adapt the standard java API. You can find a rough description of my solution in the android-developers group. It is 4 short, easily tested classes
我还查看了 google-code 项目和 git repo。由于所需项目中的明显包袱,我避开了 google-code 项目。我最终根据需要创建了自定义实现以适应标准的 Java API。您可以在android-developers 组中找到对我的解决方案的粗略描述。它是 4 个简短的、易于测试的课程
回答by user542954
Please try Google SpreadSheet APIfor Android
请尝试Android 版Google 电子表格 API
I am maintaining this project on Google Code, so if you face any problem, kindly let me know.
我在 Google Code 上维护这个项目,所以如果你遇到任何问题,请告诉我。
Cheers, Prasanta
干杯,普拉桑塔
回答by Chris S
Here's some steps to getting the Google Docs api working with an Android Eclipse project.
以下是让 Google Docs api 与 Android Eclipse 项目一起工作的一些步骤。
Spoiler: it breaks (for me) on the SAX exception
剧透:它在 SAX 异常上中断(对我而言)
1
1
Get the GData Java library(via the language guide)
2
2
Get the 3 jars from the Android Javamail port
从Android Javamail 端口获取 3 个 jars
3
3
Add the following jars in your lib folder, add them to the path using the context menu (Build path->Add)
在您的 lib 文件夹中添加以下 jar,使用上下文菜单(构建路径->添加)将它们添加到路径中
- activation.jar (javamail)
- additionnal.jar (javamail)
- mail.jar (javamail)
- gdata-client-1.0.jar
- gdata-client-meta-1.0.jar
- gdata-core-1.0.jar
- gdata-docs-3.0.jar
- gdata-docs-meta-3.0.jar
- gdata-gtt-2.0.jar
- gdata-gtt-meta-2.0.jar
- gdata-media-1.0.jar
- google-collect-1.0-rc1.jar (from the deps folder of the gdata folder)
- jsr305.jar3. (from the deps folder of the gdata folder)
- activation.jar (javamail)
- addnal.jar (javamail)
- 邮件.jar (javamail)
- gdata-client-1.0.jar
- gdata-client-meta-1.0.jar
- gdata-core-1.0.jar
- gdata-docs-3.0.jar
- gdata-docs-meta-3.0.jar
- gdata-gtt-2.0.jar
- gdata-gtt-meta-2.0.jar
- gdata-media-1.0.jar
- google-collect-1.0-rc1.jar(来自 gdata 文件夹的 deps 文件夹)
- jsr305.jar3。(来自gdata文件夹的deps文件夹)
4
4
Don't forget to add the INTERNET permission in your AndroidManifest.xml:
不要忘记在您的 AndroidManifest.xml 中添加 INTERNET 权限:
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
5
5
Try out some example code:
尝试一些示例代码:
DocsService client = new DocsService("myappname");
try
{
client.setUserCredentials("username", "password");
URL feedUri = new URL("https://docs.google.com/feeds/default/private/full/");
DocumentListFeed feed = client.getFeed(feedUri, DocumentListFeed.class);
TextView textView = (TextView) findViewById(R.id.textview);
String text = "";
for (DocumentListEntry entry : feed.getEntries())
{
text += entry.getTitle().getPlainText() + "\r\n";
}
textView.setText(text);
}
catch (AuthenticationException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (MalformedURLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (ServiceException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
6
6
Accept defeat after 2 hours, with a SaxException from logcat:
2 小时后接受失败,并带有来自 logcat 的 SaxException:
WARN/XmlParser(1599): javax.xml.parsers.ParserConfigurationException:
org.xml.sax.SAXNotRecognizedException: http://xml.org/sax/features/external-parameter-entities
...
at com.google.gdata.wireformats.input.AtomDataParser.parse(AtomDataParser.java:68)
警告/XmlParser(1599): javax.xml.parsers.ParserConfigurationException:
org.xml.sax.SAXNotRecognizedException: http://xml.org/sax/features/external-parameter-entities
...
在 com.google.gdata。 wireformats.input.AtomDataParser.parse(AtomDataParser.java:68)
This last step causes a ServiceException.
最后一步会导致 ServiceException。