Search code examples
javagoogle-docsgoogle-docs-apigoogle-drive-api

how to get text document content with the google docs api


I trying to get the content of a text document with the google docs api, this is how i get the url to export the document like text

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

but don't know how to get the content in java,

hope someone can help thx in advance


Solution

  • Please try fllowing code:

    MediaContent mc = new MediaContent();
    mc.setUri(UrlForDownload);
    MediaSource ms = docsService.getMedia(mc);
    InputStream in = ms.getInputStream();