I'm trying to use for the first time a Google API, Google Drive API, I'm authenticating the user with Google SignIn. I created a ClientId, ClientSecret and Scope after enabling Google Drive API, but I don't know how to use them. I ended up creating a HTTP client using the GoogleSignInAccount's authHeaders.
I won't need to access my files or manage them, I just need to be authenticated because I might need to download big files, using direct links doesn't work since it has a confirmation window for big files that can't be scanned.
When I try do download a public file using it's ID I always get the error below.
class GoogleHttpClient extends IOClient {
Map<String, String> _headers;
GoogleHttpClient(this._headers) : super();
@override
Future<IOStreamedResponse> send(BaseRequest request) =>
super.send(request..headers.addAll(_headers));
@override
Future<Response> head(Object url, {Map<String, String> headers}) =>
super.head(url, headers: headers..addAll(_headers));
}
class GDriveHelper {
// NOT USING
//static final clientId = "??????.apps.googleusercontent.com";
//static final clientSecret = "??????";
//static final scopes = [ga.DriveApi.DriveFileScope];
static UserController userController = Get.find();
static Future<void> download(String fileId) async {
Map<String, String> headers = await userController.googleSignInAccount.authHeaders;
var client = GoogleHttpClient(headers);
var drive = ga.DriveApi(client);
await drive.files.get(fileId).then((file){
print("FILE: $file");
});
}
}
When I call the method I get this error:
await GDriveHelper.download(fileId);
DetailedApiRequestError(status: 403, message: Insufficient Permission: Request had insufficient authentication scopes.)
ga.DriveApi.DriveFileScopetoga.DriveApi.DriveScope, what result will you obtain? In that case, please reauthorize the scope again. - TanaikeGET https://www.googleapis.com/drive/v3/files/[FILEID]?alt=media&key=[YOUR_API_KEY]. How about this? - Tanaikecurl "https://www.googleapis.com/drive/v3/files/[FILEID]?alt=media&key=[YOUR_API_KEY]". - Tanaike