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

How to create folder using google drive api in a flutter app?

我尝试在 google drive account 中的 flutter app 中创建文件夹。它显示了 bad argument(s) error。虽然我正在使用文档示例

这是我尝试执行的代码。它生成

"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()));




正如您已经完成的 Auth credentials,您可以使用这个 在 Google 驱动器中创建文件夹的简单函数。

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
              );
            });