栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用Flutter访问Google云端硬盘的appdata文件夹文件?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用Flutter访问Google云端硬盘的appdata文件夹文件?

对我来说,以下的作品,(使用HTTP包

get
post

验证令牌

您可以从返回的accoutn中检索auth令牌

signIn

Future<String> _getAuthToken() async {  final account = await sign_in_options.signIn();  if (account == null) {    return null;  }  final authentication = await account.authentication;  return authentication.accessToken;}

搜索

要在AppData目录中搜索文件,您需要添加

spaces
queryParameters并将其设置为
appDataFolder
。该文档在这方面有点误导。

final Map<String, String> queryParameters = {  'spaces': 'appDataFolder',  // more query parameters};final headers = { 'Authorization': 'Bearer $authToken' };final uri = Uri.https('www.googleapis.com', '/drive/v3/files', queryParameters);final response = await get(uri, headers: headers);

上载

要上传文件,您需要为初始上传请求设置正文的

parents
to
appDataFolder
属性。要下载文件,您只需要fileId。

final headers = { 'Authorization': 'Bearer $authToken' };final initialQueryParameters = { 'uploadType': 'resumable' };final Map<String, dynamic> metaData = {   'name': fileName,  'parents': ['appDataFolder ']};final initiateUri = Uri.https('www.googleapis.com', '/upload/drive/v3/files', initialQueryParameters);final initiateResponse = await post(initiateUri, headers: headers, body: json.enpre(metaData));final location = initiateResponse.headers['location'];

下载

要下载文件,您只需要知道

fileId
,如果您不知道,则需要使用搜索API进行检索(请参见上文)。

final headers = { 'Authorization': 'Bearer $authToken' };final url = 'https://www.googleapis.com/drive/v3/files/$fileId?alt=media';final response = await get(url, headers: headers);


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/406985.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号