您可以使用Drive REST API添加现有Google文档的新版本吗?

您可以使用Drive REST API添加现有Google文档的新版本吗?,rest,google-drive-api,Rest,Google Drive Api,想知道是否有人真的使用Drive REST API添加了文档的新版本,自动化了在驱动器中右键单击文档的手动过程,开始管理版本,上载新版本?我希望在我的案例中添加新版本的PDF 我最接近于通过Drive REST API文档找到答案的地方是这里,使用File:update: 但我不知道它是否真的会添加一个新版本,让历史版本保持原汁原味 提前感谢您的任何意见或建议 Dave答案是肯定的,只要您对文件/文件夹执行更新 Drive mGOOSvc; ... /*******************

想知道是否有人真的使用Drive REST API添加了文档的新版本,自动化了在驱动器中右键单击文档的手动过程,开始管理版本,上载新版本?我希望在我的案例中添加新版本的PDF

我最接近于通过Drive REST API文档找到答案的地方是这里,使用File:update:

但我不知道它是否真的会添加一个新版本,让历史版本保持原汁原味

提前感谢您的任何意见或建议


Dave

答案是肯定的,只要您对文件/文件夹执行更新

 Drive mGOOSvc;
 ...
/****************************************************************
   * update file in GOODrive,  see https://youtu.be/r2dr8_Mxr2M 
   * @param resId  file  id
   * @param titl  new file name (optional)
   * @param mime  new mime type (optional, "application/vnd.google-apps.folder" indicates folder)
   * @param file  new file content (optional)
   * @return      file id  / null on fail
   */
  String update(String resId, String titl, String mime, String desc, java.io.File file){
    com.google.api.services.drive.model.File gFl = null;
    if (mGOOSvc != null  && resId != null) try {
      com.google.api.services.drive.model.File meta = new File();
      if (titl != null) meta.setTitle(titl);
      if (mime != null) meta.setMimeType(mime);
      if (desc != null) meta.setDescription(desc);

      if (file == null)
        gFl = mGOOSvc.files().patch(resId, meta).execute();
      else
        gFl = mGOOSvc.files().update(resId, meta, new FileContent(mime, file)).execute();

    } catch (Exception e) { e.printStackTrace();}
    return gFl == null ? null : gFl.getId();
  }
您将使用drive.google.com->Manage versions看到该对象的新版本

它在“更新”分支中工作,但我没有测试“补丁”分支

祝你好运