Firebase_auth photoURL 无效。返回默认人像

Firebase_auth photoURL not working. Returning default person image

颤振 1.20.4; flutter_login_facebook:^0.2.1; firebase_auth:^0.18.1; firebase_core:^0.5.0; 供应商:^4.3.2;

显示名称和电子邮件有效,但照片 URL returns 这个: 我尝试在不同的设备上构建它并尝试登录到不同的 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())
              ],
            );
          }),
    ));
  }
}

这是 Bloc

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();
}

我遇到了同样的问题。 FB好像改了获取头像的方式

来源:https://developers.facebook.com/docs/graph-api/reference/user/picture/

“在开发模式下对 ASID 发出无令牌请求的应用程序将收到剪影图像作为响应。”

使用 Facebook 登录后的令牌可用于从图表中检索图像 API。问题是我需要下载图像并显示在个人资料小部件中。