flutter - 在 Flutter 中,如何通过文档 ID 访问 Google Docs 文档?
问题描述
背景
在 Google Apps 脚本中,我可以通过调用 DocumentApp 并使用 openById 方法来访问 Google Drive 中的现有文档。例如:
var documentToAccess = DocumentApp.openById(documentId);
同样,我可以通过调用 DriveApp.getFileById 访问 Google Drive 中的文件。例如:
var fileToAccess = DriveApp.getFileById(documentId);
问题
在 Flutter 中,googleapis 依赖项允许我导入多个库,包括 googleapis/drive/v3.dart、googleapis/docs/v1.dart 和 googleapis/file/v1.dart,它们提供了访问 Google Drive 中文件属性的方法,但我似乎找不到一种方法来实际获取或打开我想要处理的文件。
问题
在 Flutter 中,如何通过文档 ID 获取 Google Docs 文档,以便我可以处理该文档?
googleapis 文档和其他尝试
googleapis 文档有一些有用的资源,但尽管尝试实现这些资源,但我似乎无法得到我需要的东西。例如:
var fileToAccess = DriveApi().files.get('documentId’);
var fileToAccess = Document().documentId;
var fileToAccess = FilesResourceApi().get('documentId');
解决方案
看起来用户没有登录,所以首先,登录用户。
GoogleSignIn _googleSignIn = GoogleSignIn(
scopes: <String>[
'email',
'https://www.googleapis.com/auth/documents.readonly',
'https://www.googleapis.com/auth/drive.readonly'
],
);
要实例化客户端,您将添加如下内容:
final client = MyClient(defaultHeaders: {
'Authorization': 'Bearer ${authentication.accessToken}'
});
然后您尝试获取文档的位置:
DriveApi driveApi = DriveApi(client);
var files = await driveApi.files
.list(q: 'mimeType=\'application/vnd.google-apps.document\'');
推荐阅读
- python - 如何使用 QLineEdit text() 从 postgresql 获取数据到 QtableWidgit
- sql - 最近日期的 SQL 查询
- node.js - 使用 ejs 语法时出现问题
- c++ - 如果仅写入值,我是否需要原子?
- c++ - 在 C++ 中将浮点数与双溢出相乘
- excel - VBA 将函数结果写入活动和偏移单元格
- c# - LINQ 查询返回孙辈匹配值的祖父母
- multithreading - 使用所有物理或逻辑内核进行多处理?
- mysql - 错误代码:3813。列检查约束“customer_details_chk_2”引用其他列
- google-app-engine - 添加服务帐户时 Cloud Scheduler 显示未知错误