Facebook SDK for Android - Example app won't work

后端 未结 3 542
陌清茗
陌清茗 2021-01-30 19:14

Okey, I\'ve done all the business, followed all the steps, but still can\'t get it to work. The simple Example app that comes with the Facebook SDK, is working on the emulator a

3条回答
  •  广开言路
    2021-01-30 19:40

    If the keytool command doesn't work for you, I found a way around that stuff: you can just reverse engineer which key to put as Key Hash in the Facebook Developer section. Within your Activity just print out the Key Hash by doing:

    try {
       PackageInfo info = getPackageManager().getPackageInfo("[your package name, e.g. com.yourcompany.yourapp]", PackageManager.GET_SIGNATURES);
       for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("Hash Key:", Base64.encode(md.digest()));
       }
    } catch (NameNotFoundException e) {
    
    } catch (NoSuchAlgorithmException e) {
    
    }
    

    This worked for me. The MessageDigest class is included in the JDK. The Base64 class not. You can use this one for example.

提交回复
热议问题