How to get a detailed list of google doc revisions in Drive API

萝らか妹 提交于 2019-12-04 10:53:35

问题


I am trying to find a way to retrieve a detailed list of Google doc revisions using Google Drive API. I have tried to implement it in Java, and it does return a list of 10 revisions. However, this list is not detailed enough. If I go to Google Drive, open this file and check the revisions through "File-see revision history", it will return the same list (of 10 revisions) as I got from the Drive API. But there is a button called "Show more detailed revisions" and it will return a detailed list of revisions if I click on it.

Does anyone know how to get this detailed list through Drive API? Or is there any other alternative ways to get this detailed list of revisions?


回答1:


You should use both get and list methods to get detailed list of revisions for a google drive file; Below sample should work (I haven't test this):

    /**
       * Print detail information about revisions of the specified file.
       *
       * @param service Drive API service instance.
       * @param fileId ID of the file to print revisions for.
    */
    private static void detailedRevisions(Drive service, String fileId) {
        try {
           RevisionList revisions = service.revisions().list(fileId).execute();
           List<Revision> revisionList = revisions.getItems();

           for(Revision revision : revisionList) {
               revision = service.revisions().get(
                 fileId, revision.getId()).execute();

               System.out.println("Revision ID: " + revision.getId());
               System.out.println("Modified Date: " + revision.getModifiedDate());
               if (revision.getPinned()) {
                   System.out.println("This revision is pinned");
               }
           }
        } catch (IOException e) {
            System.out.println("An error occured: " + e);
        }
    }

Check this for a complete list of Revision class methods: https://developers.google.com/resources/api-libraries/documentation/drive/v2/java/latest/



来源:https://stackoverflow.com/questions/13107369/how-to-get-a-detailed-list-of-google-doc-revisions-in-drive-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!