如何在 flutter 应用程序中使用 google Drive api 创建文件夹?

Ant*_*oun 5 google-api drive dart google-drive-api flutter

我尝试在flutter appa 中创建文件夹google drive account。它向我展示了一个bad argument(s) error. 虽然我正在使用文档示例

这是我尝试做的代码。它产生

“错误的参数”错误。

final _SCOPES = [drive.DriveApi.DriveScope];

  void adrive(){

clientViaServiceAccount(_credentials,_SCOPES).then(onValue).catchError((e)=>print(e));
  }


  FutureOr onValue(AuthClient client)  {
    //drive.DriveApi(client).files.list().then((value)=>print(value.items[0]));
    // The previous line works fine
    drive.File r = new drive.File();
    r.mimeType = "application/vnd.google-apps.folder";
    r.title = "hello";

    drive.DriveApi(client).files.insert(r,uploadOptions: commons.UploadOptions.Resumable).then((f)=>print(f.mimeType+" "+f.originalFilename))
          .catchError((ex)=>print(ex.toString()));




Run Code Online (Sandbox Code Playgroud)

anm*_*ail 4

正如您已经完成的那样Auth credentials,您可以使用这个简单的功能在 Google Drive 中创建文件夹。

clientViaServiceAccount(credentials, scopes).then((http_client) async {
              var _drive = v3.DriveApi(http_client);
              var _createFolder = await _drive.files.create(
                v3.File()
                  ..name = 'FileName'
                  ..parents = ['1f4tjhpBJwF5t6FpYvufTljk8Gapbwajc'] // Optional if you want to create subfolder
                  ..mimeType = 'application/vnd.google-apps.folder',  // this defines its folder
              );
            });
Run Code Online (Sandbox Code Playgroud)