Android Facebook SDK 4.5.0 Login Error Invalid key hash error when trying to login again

I implemented the Facebook login button as described in the https://developers.facebook.com/docs/facebook-login/android developer guide with permissions to view the profile and email.

When I click on the login button, the Facebook application opens, and then I can log in and get user data from Facebook. After this moment, the Facebook button automatically switches to the "Exit" button. And when it is pressed, it logs out. So far, this works well.

As soon as I log out of the Facebook account on my side of the application and you want to re-login using the Facebook button, Facebook will fail with a key error. If I go to the account settings in the Facebook application and remove my application from the list, then re-login returns success.

I also tried the solution here is the issue of logging into the Android Facebook system , but it also did not work. To clear, I use this code (found the common name pref in the AccessTokenCache class):

SharedPreferences fbSharedPreferences = this.getSharedPreferences("com.facebook.AccessTokenManager.SharedPreferences", 0); if (fbSharedPreferences != null) { fbSharedPreferences.edit().clear().commit(); } 

I am using the Facebook SDK 4.5. I am testing a real Facebook account. My keys and application hashes are set in the Facebook application settings.

PS Question name depends on Facebook Login-Logout Issue Invalid key hash error when trying to log in again (which has no solution).

+5
source share
1 answer

I had the same problem, you need to remove the application from the facebook application and then log out. The following function will do the trick.

 public void disconnectFromFacebook() { if (AccessToken.getCurrentAccessToken() == null) { return; // already logged out } new GraphRequest(AccessToken.getCurrentAccessToken(), "/me/permissions/", null, HttpMethod.DELETE, new GraphRequest .Callback() { @Override public void onCompleted(GraphResponse graphResponse) { LoginManager.getInstance().logOut(); } }).executeAsync(); } 
+2
source

Source: https://habr.com/ru/post/1233274/


All Articles