android connect facebook invalid keyhash

北战南征 提交于 2019-12-05 08:01:04

问题


i'm working android facebook sdk. i have problem when divice has installed facebook application(invalid key hash) i recived keyhash in this code

public class SpleshScreen extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_splesh_screen);

    try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "mypackage", 
                PackageManager.GET_SIGNATURES);
        for (android.content.pm.Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.wtf("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
            }
    } catch (NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }

    Thread background = new Thread() {

        public void run() {

            try {
                // Thread will sleep for 2 seconds
                sleep(2 * 1000);


                //
                // Log.e("asdasdasdasd",my_json );

                // After 2 seconds redirect to another intent
                Intent in = new Intent(getApplicationContext(),
                        MainmoviesActivity.class);
                startActivity(in);

                // Remove activity
                finish();

            } catch (Exception e) {

            }
        }
    };

    // start thread
    background.start();
}

}

and i added this keyhash in my facebook app . i have problem only when divice has facebook application(when i run my app with USB ) what am i doing wrong? if anyone knows solution please help me


回答1:


Its because the generate hash key is wrong.

To solve follow this steps:

Paste the following code in oncreate().

try {
    PackageInfo info = getPackageManager().getPackageInfo(
            "com.example.packagename", 
            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) {

}

see this thread

https://stackoverflow.com/a/23863110/2176734

this will surely solve your problem.




回答2:


1.go to developer.facebook.com

2.select your application

3.Click settings

4.click Add Platform

5.add all mandatory fields

6.add your key hashes there

7.Click save changes

now check



来源:https://stackoverflow.com/questions/26402449/android-connect-facebook-invalid-keyhash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!