Search code examples
javaoauthgoogle-docsgoogle-docs-api

Error exporting a document in google docs api


I'm trying to retrieve a document like this:

  client.setAuthSubToken(token);
  String contentUri = "https://docs.google.com/feeds/download/documents/Export?docID="+ entry.getDocId()
                            + "&exportFormat=txt&format=txt";

  MediaContent mc = new MediaContent();
  mc.setUri(contentUri);

  MediaSource ms = client.getMedia(mc);
  InputStream inStream = ms.getInputStream();

But am getting the next error:

com.google.appengine.repackaged.org.apache.http.impl.client.DefaultRequestDirector handleResponse ADVERTENCIA: Authentication error: Unable to respond to any of these challenges: {authsub=WWW-Authenticate: AuthSub realm="https://www.google.com/accounts/AuthSubRequest"}

Do not why if my client is authenticated, hope some one can help, thanks in advance.


Solution

  • Maybe this will help:

    1. Replace docId parameter with id parameter

      contentUri = "https://docs.google.com/feeds/download/documents/export/Export?id=" + entry.getDocId() + "&exportFormat=txt&format=txt";
      
    2. Use directly the method for obtaining the uri (This is recommended)

      String contentUri = ((MediaContent) entry.getContent()).getUri();
      contentUri = contentUri + "&exportFormat=txt&format=txt";