4
votes

I am trying to backup the application data of my android app on Google Drive. Therefore I request access to the https://www.googleapis.com/auth/drive.appdata, https://www.googleapis.com/auth/drive.file scopes using the google_sign_in package.

I created a project on the Google Developer Console, enabled the Drive API and added the scopes to the OAuth Consent Screen and added an OAuth Client ID with the package name and the SHA-1 of the debug key.

The application works fine if I don't request any scopes, requesting the "drive" scopes however makes the consent screen being stuck and it keeps loading forever. Is there anything that I am missing?

Below are the code of the application and the stuck screen loading Consent Screen Loading

import 'package:flutter/material.dart';
import 'package:google_sign_in/google_sign_in.dart';

Future<GoogleSignInAccount> handleSignIn() async {
  try {
    return await GoogleSignIn(
      scopes: [
        'https://www.googleapis.com/auth/drive.appdata',
        'https://www.googleapis.com/auth/drive.file',
      ],
    ).signIn();
  } catch (error) {
    print(error);
    return null;
  }
}

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: Text(""),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              FlatButton(
                child: const Text("Login with Google"),
                onPressed: () {
                  () async {
                    final signInResult = await handleSignIn();
                    print(signInResult);
                  }();
                },
              ),
            ],
          ),
        ),
      )
    );
  }
}
1
Have you managed to fix this yet? It should be working. Try on a different emulator or a real device. I'm stuck on the next step, getting the login credentials and accessing appdata folder. Please let me know if you know how to and I'll open a question.Dpedrinha
Maybe the same issue as here? stackoverflow.com/questions/58073423/…stefan222
@Dpedrinha the way I could get it working was by using another Account to sign in. I managed to get the appdata/drive working.surrz
Did you happen to revoke access from the Google account page by any chance? I'm running into the same exact issue. It happened when I went to my Google account to revoke access as a test and then when I tried to sign back in with the same account, it's been stuck at the consent screen. I've even tried different Google accounts that never had been used and it still didn't work.Brian

1 Answers

0
votes

Going through the comments, it seems that the code works fine and the issue was caused by the account used - it's likely from the permission set on the account. If you're still having issues, I suggest logging the errors for more details of the issue.