2013년 8월 7일 수요일

how to get 100% correct key hash for facebook auth

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Add code to print out the key hash
    try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "com.facebook.samples.hellofacebook", 
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
            }
    } catch (NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }

Put the above code in any class file of your app to get correct key hash. Change "com.facebook.samples.hellofacebook" to your package name. Check log to get key hash and put the hash in the setting of facebook app.  

댓글 없음:

댓글 쓰기