【发布时间】:2020-01-09 21:21:24
【问题描述】:
我正在尝试在 Google Drive 上备份我的 android 应用程序的应用程序数据。因此,我请求使用 google_sign_in 包访问 https://www.googleapis.com/auth/drive.appdata、https://www.googleapis.com/auth/drive.file 范围。
我在 Google 开发者控制台上创建了一个项目,启用了 Drive API 并将范围添加到 OAuth 同意屏幕,并添加了一个带有包名称和调试密钥 SHA-1 的 OAuth 客户端 ID。
如果我不请求任何范围,应用程序可以正常工作,但请求“驱动器”范围会使同意屏幕卡住并且它会永远加载。 我有什么遗漏的吗?
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);
}();
},
),
],
),
),
)
);
}
}
【问题讨论】:
-
你解决了这个问题了吗?它应该工作。尝试不同的模拟器或真实设备。我被困在下一步,获取登录凭据并访问 appdata 文件夹。如果您知道如何操作,请告诉我,我会提出问题。
-
可能和这里的问题一样? stackoverflow.com/questions/58073423/…
-
@Dpedrinha 我可以让它工作的方式是使用另一个帐户登录。我设法让 appdata/drive 工作。
-
您是否碰巧撤消了 Google 帐户页面的访问权限?我遇到了同样的问题。它发生在我去我的谷歌帐户以撤销访问作为测试,然后当我尝试使用同一个帐户重新登录时,它一直停留在同意屏幕上。我什至尝试过从未使用过的其他 Google 帐户,但仍然无法使用。
-
你可以在这里查看答案:stackoverflow.com/questions/68890537/…
标签: android flutter dart google-drive-api google-signin