在 Android 上从 Google 云端硬盘下载 Google Sheets 电子表格

发布于 2024-09-01 12:23:04 字数 702 浏览 11 评论 0原文

我正在开发一个 Android 应用程序,它使用 gdata-java-client 下载仅用于显示的文档。到目前为止,我有一个应用程序可以通过服务进行身份验证并显示用户文档列表。当用户选择文档时,系统会针对文档本身进行另一个查询。对 txt、html、rtf 和 doc 文件的请求效果很好,但是当我请求 .csv 或 .xsl 格式的电子表格时,结果是意外的。

我正在使用 HTTPResponse 对象来存储 HTTPRequest 的结果。当我请求 .csv 或 .xsl 格式的文档时,HTTPResponse.parseAsString() 方法会生成整个 html 页面,该页面似乎是 Google Docs 主页。听起来很奇怪,但结果是登录页面的实际 html。 HTTPResponse.getStatusMessage 返回 200。

似乎我在这里缺少一些简单的东西。 HTTPResponse 是否还有另一个包含 .csv 数据的属性?

我非常确定我使用正确的 uri 来下载电子表格,因为当我通过浏览器下载时它可以工作。无论如何,这里有一个示例 uri:

https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=0AsE_6_YIr797dHBTUWlHMUFXeTV4ZzJlUGxWRnJXanc&exportFormat=csv

提前感谢您的帮助:)

I am working on an Android app that uses the gdata-java-client to download documents for display only. So far I have an application that authenticates with the services and displays a list of user documents. When the user selects a document another query is made for the documents itself. A request for txt, html, rtf and doc files works well, however when I request a spreadsheet in either .csv or .xsl format the result is unexpected.

I'm using an HTTPResponse object to store the result of a an HTTPRequest. When I request a document in .csv or .xsl format the HTTPResponse.parseAsString() method produces an entire html page which appears to be the Google Docs home page. Sounds strange, but the result is the actual html for the login page. The HTTPResponse.getStatusMessage returns a 200.

Seems like I am missing something simple here. Is there another property of the HTTPResponse that contains the .csv data?

I am pretty sure that I am using the correct uri for downloading spreadsheets because it works when I download through my browser. In any case here is an example uri:

https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=0AsE_6_YIr797dHBTUWlHMUFXeTV4ZzJlUGxWRnJXanc&exportFormat=csv

Thanks in advance for any help :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

凉风有信 2024-09-08 12:23:04

我还没有看到您的代码,但最肯定的问题是您正在使用 ClientLogin,并且使用“writely”服务对文档列表 API 进行了身份验证。但是,由于导出电子表格将访问 Spreadsheets.google.com,因此您需要使用 ClientLogin 针对“wise”服务进行身份验证。对于 Java,这意味着使用 Spreadsheets Java 客户端库,其记录如下:
http://code.google.com/apis/documents/docs /3.0/developers_guide_java.html#DownloadingSpreadsheets

请注意顶部标有“重要”的注释,该注释链接到此处:
http://code.google.com/apis/documents/docs /3.0/developers_guide_java.html#DownloadingSpreadsheetsClientLogin

在该链接中,详细介绍了如何使用 SpreadsheetClient 实例。

祝你好运 :)

I haven't seen your code, but most certainly the issue is that you're using ClientLogin, and are authenticated for the Documents List API using the 'writely' service. However, since exporting a spreadsheet will hit spreadsheets.google.com, you'll need to use ClientLogin to authenticate against the 'wise' service. From Java, that means using the Spreadsheets Java client library, which is documented here:
http://code.google.com/apis/documents/docs/3.0/developers_guide_java.html#DownloadingSpreadsheets

Note the note labeled 'Important' at the top there, which links here:
http://code.google.com/apis/documents/docs/3.0/developers_guide_java.html#DownloadingSpreadsheetsClientLogin

At that link, using a SpreadsheetClient instance is detailed.

Good luck :)

榆西 2024-09-08 12:23:04

我对文档列表 API 不太熟悉,无法了解,但从您的描述来看,您可能遇到了文档列表 API 中的错误,对我来说这听起来像是一个需要修复的重要问题。

请在文档列表 API 论坛上报告您的问题,以增加知识渊博的人能够调查此问题的机会:

http://www.google.com/support/forum/p/apps-apis/label?lid=5c316c702e844c99&hl=en

I am not familiar enough with the Documents List API to know, but from your description it sounds like you may have encountered a bug in the Documents List API, and it sounds to me like an important problem to fix.

Please report your issue at the Documents List API forum to increase the chance that someone knowledgeable would be able to look into this issue:

http://www.google.com/support/forum/p/apps-apis/label?lid=5c316c702e844c99&hl=en

怀中猫帐中妖 2024-09-08 12:23:04

现在是 2017 年,现在有一种全新的做事方式。 GData、GData API(例如文档列表 API、ClientLogin 和云端硬盘下载 URL)现已过时。取而代之的是 Drive API、Sheets API 以及通过 Android 应用程序与 Google 技术集成的更原生的方式:适用于 Android 的 Google API 客户端库。如果您正在使用服务器,还有一个 适用于 Java 的 Google API 客户端库相反。

如果您想在电子表格上执行面向文档的操作,您可以使用 Google 表格API 并使用上面的客户端库来执行此操作。现在举一些例子...这里有 Android 快速入门代码示例以及Sheets API 的更通用的 Java 快速入门代码示例。传递 JavaDocs 参考不会有什么坏处Sheets API 之一。最新的 Sheets API 提供了旧版本中不可用的功能,即为开发人员提供对 Sheet 的编程式、面向文档的访问,就像使用用户界面一样(创建冻结行、执行单元格格式化、调整行/列大小、添加数据透视表、创建图表等)

但是,要执行文件级访问,例如OP的问题,您可以使用Google 云端硬盘 API。甚至还有 Android 版 Google Drive API,其中包括 专门用于检索文档内容的文档页面。如果您是该库的新手,这里还有Drive API Android 快速入门示例应用作为其他代码示例来帮助您入门。以下是适用于 Android 的 Drive API 类参考文档也是。

It's 2017, and there's a completely new way of doing things now. GData, GData APIs like the Documents List API, ClientLogin, and Drive download URLs are all now obsolete. In their place are a Drive API, a Sheets API, and a more native way of integrating with Google technologies from Android apps: the Google APIs Client Library for Android. There's also a Google APIs Client Library for Java if you're doing server-side instead.

If you want to perform document-oriented operations on spreadsheets, you'd use the Google Sheets API and do so using the Client Library above. Now for some examples... here's the Android quickstart code sample as well as the more general Java quickstart code sample for the Sheets API. Can't hurt to pass along the JavaDocs reference for the Sheets API either. The latest Sheets API provides features not available in older releases, namely giving developers programmatic document-oriented access to a Sheet as if you were using the user interface (create frozen rows, perform cell formatting, resizing rows/columns, adding pivot tables, creating charts, etc.)

However, to perform file-level access, such as in the OP's question, you'd use the Google Drive API. There's even a Google Drive API for Android, including a docs page specifically on retrieving document contents. If you're new to this library, here is the Drive API Android quickstart sample app as well as other code samples to get you started. Here are the Drive API for Android class reference docs too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文