您可以使用 Drive REST API 添加现有 Google 文档的新版本吗?
Can you add a new version of an existing Google Doc using the Drive REST API?
想知道是否有人真的使用 Drive REST API 添加了新版本的文档,自动执行右键单击 Drive 中的文档、管理版本、上传新版本的手动过程?我希望在我的案例中添加新版本的 PDF。
我最接近通过 Drive REST API 文档找到答案的是这里,使用 File:update:
https://developers.google.com/drive/v2/reference/files/update
但我看不到它是否真的会添加新版本,保留历史版本。
在此先感谢您的任何意见或建议,
戴夫
答案是肯定的,只要您对 file/folder、
执行更新
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 -> 管理版本...
它在 'update' 分支中工作,但我没有测试 'patch' 分支。
祝你好运
想知道是否有人真的使用 Drive REST API 添加了新版本的文档,自动执行右键单击 Drive 中的文档、管理版本、上传新版本的手动过程?我希望在我的案例中添加新版本的 PDF。
我最接近通过 Drive REST API 文档找到答案的是这里,使用 File:update:
https://developers.google.com/drive/v2/reference/files/update
但我看不到它是否真的会添加新版本,保留历史版本。
在此先感谢您的任何意见或建议,
戴夫
答案是肯定的,只要您对 file/folder、
执行更新 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 -> 管理版本...
它在 'update' 分支中工作,但我没有测试 'patch' 分支。
祝你好运