0

EDIT: Everything except pdf seems to give the correct revision. Only if I request a pdf, do I get the latest revision regardless of the revision id i passed


This should be simple, but I'm always getting the head revision instead of the previous versions when I try to download.

Here's a snippet of my code

RevisionList revList = service.revisions().list(fileId)
         .setMaxResults(10)
         .execute();
// Got all revisions here
List<Revision> revisions = revList.getItems();
if (revisions == null || revisions.size() == 0) {
    System.out.println("No revisions found.");
} else {
    // Got the first revision I made to the file
    Revision rev = revisions.get(0);
    // Date is in 2015 for this particular revision
    String date = rev.getModifiedDate().toString();
    String filePath = System.getProperty("user.dir") + "/" +
            date.substring(0, date.indexOf('T'))+".pdf";            
    OutputStream out = new FileOutputStream(filePath);
    MediaHttpDownloader downloader =
        new MediaHttpDownloader(HTTP_TRANSPORT, service.getRequestFactory().getInitializer());
    downloader.setProgressListener(new MediaHttpDownloaderProgressListener() {
        public void progressChanged(MediaHttpDownloader downloader) {
            switch (downloader.getDownloadState()) {
                case MEDIA_IN_PROGRESS:
                    System.out.println(downloader.getProgress());
                    break;
                case MEDIA_COMPLETE:
                    System.out.println("Download is complete!");
            }
        }
    });
    downloader.download(new GenericUrl(rev.getExportLinks().get("application/pdf")), out);
}
abhipil
  • 164
  • 2
  • 13
  • 2
    Looks like this is related to the [Drive PDF revision bug](https://code.google.com/a/google.com/p/apps-api-issues/issues/detail?id=4008) that's also mentioned in [this post](http://stackoverflow.com/a/34292298/4625829) where the revision id is being ignored. – AL. Apr 17 '17 at 06:12
  • @AL yep, you're right that's the issue. And it's more than a year since it was raised. And v3 explicitly disallows getting gdoc revisions. I might have to rethink my project. But thanks anyway. – abhipil Apr 18 '17 at 03:33
  • I get same behavior in my code, for a google doc with five revisions, each PDF exportlink always retrieve latest doc version. It works well using another MIMETYPE, like docx or png. – Jesus Mostajo Jul 14 '20 at 09:28

0 Answers0