I have built a "Log In with Facebook" button for my app, it's working normally in the virtual device, but after I built my app to apk and test it on the real device, there is a problem "Invalid key hash. The key hash lULhSMXXXXXXXXXX does not match any stored key hashes. Configure your app key hashes at http://developers.facebook.com/apps/XXXXXXX. Then I go to developers.facebook.com/apps/XXXXXXX and add the key hash lULhSMXXXXXXXXXXXX to setting and it worked normally. So I have a question, if I install my app in many different devices, how can I make the "Log In with Facebook" button working without have to add a key hash for each device like this. Thank you. This is my code
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.setReadPermissions(Arrays.asList("email"));
callbackManager = CallbackManager.Factory.create();
loginButton.registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
// App code
loginFacebook(loginResult);
}
@Override
public void onCancel() {
// App code
}
@Override
public void onError(FacebookException exception) {
// App code
}
});
private void loginFacebook(final LoginResult loginResult) {
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
String userId = null;
String name = null;
try {
userId = object.getString("id");
name = object.getString("name");
} catch (JSONException e) {
e.printStackTrace();
}
Profile profile = Profile.getCurrentProfile();
Log.d("Shreks Fragment onSuccess", "" + profile);
Intent i = new Intent(LoginActivity.this, Intent.class);
startActivityForResult(i, 0);
finish();
}
});
request.executeAsync();
}