I am getting this error. When I try to sign in with facebook to my app. When I first time authentication it will correctly working. After I unistalled my application and now
This problem occurs because you've already authenticated the app via Facebook and your code may contain Authenticate every time Facebook (Find and Remove that).
Follow these steps:
Go to Facebook settings.
Remove your app.
Make sure you've added Facebook Login in Facebook developer page and you've enabled Client OAuth Login.
Go to your code and override the callback method:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mFacebookCallbackManager.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
Intent secondActivityIntent = new Intent(this, RedirectActivity.class);
startActivity(secondActivityIntent);
}
}
In the Oncreate method, call the AccessToken:
accessTokenTracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(
AccessToken oldAccessToken,
AccessToken currentAccessToken) {
// Set the access token using
// currentAccessToken when it's loaded or set.
}
};
// If the access token is available already assign it.
accessToken = AccessToken.getCurrentAccessToken();
if (accessToken != null && !accessToken.isExpired())
{
GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
if(null != object) {
try
{
Intent i = new Intent(MainActivity.this, Feedback.class);
startActivity(i);
String email = object.getString("email");
String birthday = object.getString("birthday");
}
catch (Exception ex)
{
Toast.makeText(MainActivity.this, ex.toString(), Toast.LENGTH_SHORT).show();
}
} else {
// call your authentication process
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,birthday,link");
request.setParameters(parameters);
request.executeAsync();
}
The error occurs because of invalid hash key.
We can create Hash key using the below command and update the same here under Settings-> Basic -> Android HashKeys
keytool -exportcert -alias ADD_RELEASE_KEY_ALIASE_HERE -keystore ADD_UR_KEYSTORE_PATH_HERE | openssl sha1 -binary | openssl base64
You can find the Relase Key Alias of your keystore using the below command if needed:
keytool -list -keystore ADD_UR_KEYSTORE_PATH_HERE
I have also experience an issue like by using the above HashKey the login works fine if I install the release APK directly to the device, But when I upload the APK to Play Store and install app from store then it shows the same Login failed error. The fix for this is as follows:
I faced the same problem.
It was a mistake on my side.
keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64
When typed this command, it prompted Enter keystore password:. I was giving the keyPassword instead storePassword and it didn't gave any error message instead generated a different hash!
I had the same problem on my Redmi Note 3. Tested on Samsung. No problems. Wonder if it is Redmi specific.
I faced the same issue and I found that the hash key which I have generated to put in facebook developer console is not proper. I tried to generate hash key from different PC and it asked me to enter password for that particular keystore which was not the case in my PC. So make sure that you will asked to enter key store password while creating hash key then insert that hash key into facebook developer console.
Command to generate hash key:
keytool -exportcert -alias TYPE ALIAS HERE -keystore KEY_STORE_FILE_PATH_HERE | openssl sha1 -binary | openssl base64
I also Face this problem .Update your key hash on Facebook