如何在Drive API中获取Google文档修订版的详细列表 [英] How to get a detailed list of google doc revisions in Drive API

查看:138
本文介绍了如何在Drive API中获取Google文档修订版的详细列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种方法来使用Google Drive API检索Google文档修订版的详细清单。我试图用Java实现它,它确实返回了10个修订版的列表。但是,这个清单不够详细。如果我访问Google Drive,打开此文件并通过文件 - 查看修订历史记录检查修订版本,它将返回与Drive API相同的列表(10个修订版)。但有一个名为显示更详细的修订的按钮,如果点击它,它将返回修订版的详细列表。

有人知道如何通过Drive API获取此详细清单吗?或者有没有其他替代方式来获得修订的这个清单?


解决方案

您应该同时使用的获取 list 方法来获取谷歌驱动器文件修订版的详细列表;下面的示例应该可以工作(我还没有测试过):

  / ** 
*打印关于修订的详细信息的指定文件。
*
* @param服务Drive API服务实例。
* @param fileId打印修订版本的文件ID。
* /
private static void detailedRevisions(Drive service,String fileId){
try {
RevisionList revisions = service.revisions().list(fileId).execute();
列表<修订> revisionList = revisions.getItems(); (修订版本: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);

$ b} catch(IOException e){
System.out.println(发生错误:+ e);


$ / code>

检查这个版本的类方法的完整列表:
https://developers.google。 com / resources / api-libraries / documentation / drive / v2 / java / latest /

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?

解决方案

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/

这篇关于如何在Drive API中获取Google文档修订版的详细列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆