我正在制作一个 Flutter 移动应用程序,并尝试将相机拍摄的图像保存到特定的 Google 驱动器帐户进行存储。我已从我的 Google 帐户获取服务帐户 JSON 文件进行身份验证。
这是我正在使用的代码:
import 'dart:io' as io;
import 'package:googleapis/drive/v3.dart' as ga;
import 'package:googleapis_auth/auth.dart';
import 'package:googleapis_auth/auth_io.dart';
uploadFileToGoogleDrive(io.File fileToUpload) async {
// send authorization to access Google Drive
// from https://pub.dev/packages/googleapis_auth
ServiceAccountCredentials accountCredentials = new ServiceAccountCredentials.fromJson({
//my service account JSON information goes here
});
List<String> scopes = [ga.DriveApi.DriveFileScope, ga.DriveApi.DriveScope];
try {
// authenticates with Google Drive with our service account credentials
AuthClient client = await clientViaServiceAccount(
accountCredentials, scopes);
ga.DriveApi drive = ga.DriveApi(client);
ga.File file = …Run Code Online (Sandbox Code Playgroud)