Search code examples
androidiosflutterfacebookhash

Facebook login, problem with hash key - Flutter , How to generate Facebook Hashkey in flutter?


A window appears with the entrance to Facebook and when you click continue to arise an error

SERVER_ERROR: [code] 1349195 [message]: the key hash does not match any of the saved hashes

login() async {
    final facebookLogin = new FacebookLogin();
    final result = await facebookLogin.logInWithReadPermissions(['email']);
    switch (result.status) {
      case FacebookLoginStatus.loggedIn:
        print(result.accessToken.token);
        Navigator.of(context).pushReplacementNamed('/home_screen');
        break;
      case FacebookLoginStatus.cancelledByUser:
        print('CANCELED BY USER');
        break;
      case FacebookLoginStatus.error:
        print(result.errorMessage);
        break;
    }
  }

Solution

    1. Go to your output apk files (Usually <project_root>\build\app\outputs\flutter-apk).

    2. Use keytools to get the SHA1 value (run in terminal / git bash):

      keytool -printcert -jarfile app-debug.apk

    3. Convert the HEX value to base64 to get value that ends with =. (i.e. Use this site. Be aware to have at Input type selected Hex. And delete all : between SHA1 key groups -> AB:CD:EF = wrong, but ABCDEF = correct)

    4. Update that value to key hashes under your android platform.