rest - 如何使用顶点在谷歌驱动器的谷歌文档中添加正文(内容)
问题描述
我们想在谷歌驱动器中创建一个谷歌文档。并想将数据添加到谷歌文档中。我们现在正在驱动器中创建文件,但未添加文档的正文(内容)。
下面是用于创建文件的代码
public static void createDocument(String folderId, String documentName) {
HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setEndpoint('https://www.googleapis.com/drive/v2/files');
req.setHeader('Authorization', 'Bearer '+accessToken);
req.setHeader('content-type', 'application/json');
req.setTimeout(60*1000);
String body = '{"title":"'+ documentName +'.txt","parents":[{"id":"'+ folderId +'"}],"body": {"content": "Text of document"}}';
req.setBody(body);
Http http = new Http();
HttpResponse res = http.send(req);
}
所以你能帮助我们吗?
解决方案
我们想在谷歌驱动器中创建一个谷歌文档。
要在 Google 驱动器中创建文档,您应该使用 Google 驱动器 API v3创建方法文件创建分为两部分,元数据和文件流。您似乎正在尝试将文件的内容添加为元数据的一部分。它不是元数据的一部分,它必须作为文件流上传。 管理上传
并想将数据添加到谷歌文档中。
您需要了解 Google drive api 是一个文件存储 api,只是它无法写入文件本身。为此,您应该使用 Google Documents api,它允许您写入 google doc 文件。
我们现在正在驱动器中创建文件,但未添加文档的正文(内容)。
您还在使用 google drive v2,您应该考虑切换到 google drive v3。
推荐阅读
- c# - 从 div 中抓取
- android - ImageView 在 MaterialCardView 中垂直居中
- sql - 制作复合主键时,何时会被视为 OVERKILL?
- javascript - 使用 Javascript 动态创建的表保存到 sql 的 MVC VB.NET 网页
- mongodb - Mongo Dart 子文档更新和编辑 [已解决]
- python - TF-IDF 向量示例(帮助)
- sql - 如何在 SQL Server 中的字符串中添加换行符
- javascript - 仅当省略号超过指定字符数时才添加省略号
- linux - 当 CMD 是 shell 脚本时,如何在 Alpine Docker 上捕获 Ctrl + C 或捕获信号
- json - 如何从 JSON 中的重复元素中获取值?