Firebase_auth photoURL 不起作用。返回默认人物图像
Posted
技术标签:
【中文标题】Firebase_auth photoURL 不起作用。返回默认人物图像【英文标题】:Firebase_auth photoURL not working. Returning default person image 【发布时间】:2021-01-17 05:42:35 【问题描述】:颤振 1.20.4; flutter_login_facebook:^0.2.1; firebase_auth:^0.18.1; firebase_core:^0.5.0; 提供者:^4.3.2;
显示名称和电子邮件有效,但 photoURL 返回: 我尝试在不同的设备上构建它并尝试登录不同的 Facebook 帐户。 https://graph.facebook.com/1757577617747458/picture
我的主屏幕
class _HomeState extends State<Home>
StreamSubscription<User> homeStateSubscription;
@override
void initState()
var authBloc = Provider.of<AuthBloc>(context, listen: false);
homeStateSubscription = authBloc.currentUser.listen((fbUser)
if (fbUser == null)
Navigator.of(context)
.pushReplacement(MaterialPageRoute(builder: (context) => Login()));
);
super.initState();
@override
Widget build(BuildContext context)
var authBloc = Provider.of<AuthBloc>(context);
return Scaffold(
body: Center(
child: StreamBuilder<User>(
stream: authBloc.currentUser,
builder: (context, snapshot)
if (!snapshot.hasData) return CircularProgressIndicator();
print(snapshot.data.email);
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(snapshot.data.displayName,
style: TextStyle(fontSize: 35.0)),
SizedBox(
height: 20.0,
),
CircleAvatar(
backgroundImage: NetworkImage(
snapshot.data.photoURL + '?width=500&height500'),
radius: 60.0,
),
SizedBox(
height: 100.0,
),
SignInButton(Buttons.Facebook,
text: 'Sign out of Facebook',
onPressed: () => authBloc.logout())
],
);
),
));
这是集团
class AuthBloc
final authService = AuthService();
final fb = FacebookLogin();
Stream<User> get currentUser => authService.currentUser;
loginFacebook() async
final res = await fb.logIn(permissions: [
FacebookPermission.publicProfile,
FacebookPermission.email
]);
switch (res.status)
case FacebookLoginStatus.Success:
print('It worked');
//Get Token
final FacebookAccessToken fbToken = res.accessToken;
//Convert to Auth Credential
final AuthCredential credential =
FacebookAuthProvider.credential(fbToken.token);
//User Credential to Sign in with Firebase
final result = await authService.signInWithCredentail(credential);
print('$result.user.displayName is now logged in');
break;
case FacebookLoginStatus.Cancel:
print('The user canceled the login');
break;
case FacebookLoginStatus.Error:
print('There was an error');
break;
logout()
authService.logout();
我的身份验证服务
class AuthService
final _auth = FirebaseAuth.instance;
Stream<User> get currentUser => _auth.authStateChanges();
Future<UserCredential> signInWithCredentail(AuthCredential credential) =>
_auth.signInWithCredential(credential);
Future<void> logout() => _auth.signOut();
【问题讨论】:
【参考方案1】:我遇到了同样的问题。看来FB改变了获取头像的方式。
来源:https://developers.facebook.com/docs/graph-api/reference/user/picture/
“在开发模式下对 ASID 发出无令牌请求的应用程序将收到一个剪影图像作为响应。”
使用 Facebook 登录后的令牌可用于从图形 API 检索图像。问题是我需要下载图片并显示在个人资料小部件中。
【讨论】:
以上是关于Firebase_auth photoURL 不起作用。返回默认人物图像的主要内容,如果未能解决你的问题,请参考以下文章
Flutter firebase_auth signInWithCredential 在android上不起作用
更新用户个人资料照片不会使用 currentUser.photoUrl 更新它
致命错误:找不到模块“firebase_auth”@import firebase_auth
GeneratedPluginConstraint,致命错误:找不到模块“firebase_auth”@import firebase_auth;