Question

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 :)

Was it helpful?

Solution

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

OTHER TIPS

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 :)

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top