登录错误: 登录到此应用程序时出错。请稍后再试

我得到这个错误。当我试图登录我的应用程序与 Facebook。 当我第一次验证它将正常工作。在我卸载了我的应用程序后,现在试图在 Facebook 上注册,我得到了这个错误。

另一个问题 : 在 device1进行身份验证后,尝试在 device2上登录 facebook 也会出现同样的错误。

我发现的解决方案: 当我从 Facebook 应用程序设置中删除应用程序认证时,它在上面的场景中工作,但是这不是一个好的解决方案,我们如何告诉用户去做这个动作?

btnFbLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(accessToken != null) {
boolean expires = accessToken.isExpired();
if(!expires) {
performFbLoginOrSignUp(accessToken);
}
} else {
LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
callbackManager = CallbackManager.Factory.create();


if (loginButton != null) {
loginButton.setReadPermissions("public_profile", "email", "user_friends");


if (CommonUtil.isConnectingToInternet(LoginActivity.this)) {
loginButton.performClick();


loginButton.setPressed(true);


loginButton.invalidate();


loginButton.registerCallback(callbackManager, mCallBack);


loginButton.setPressed(false);


loginButton.invalidate();
}
}
}
}
});

Error page

在 Facebook 的例子中也有一个问题: GitHub 链接的 Facebook 例子

重现的步骤 :

  1. 启动应用程序登录与 Facebook 验证 FB 配置文件。

  2. 卸载应用程序并重新安装。

  3. 现在尝试登录 Facebook。

  4. 将发生上述错误。因为我们已经验证,所以需要访问 fb 配置文件。但在这里,我们面临的问题。

  5. 这里没有显示已经验证的页面。

  6. 我在设备红米Note 3中使用了本地 FB 应用程序

130689 次浏览

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:

  1. Go to Facebook settings.

  2. Remove your app.

  3. Make sure you've added Facebook Login in Facebook developer page and you've enabled Client OAuth Login.

  4. 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);
    }
    }
    
  5. 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();
    }
    

I also Face this problem .Update your key hash on Facebook

  1. Remove app from user settings in Facebook (account).

  2. Uninstall the app.

  3. Get the new hash using the release or new debug keystore. Use this command:

    keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64
    
  4. Add the new hash on Facebook dashboard.

I had the same problem on my Redmi Note 3. Tested on Samsung. No problems. Wonder if it is Redmi specific.

I was facing the same issue. I had my keyhashes defined perfectly, was still facing the same issue. I was not able to login even for the first time.

Solution to my problem was:

  1. Go to your app's dashboard here

  2. On the left pane, under products tab, ensure that you have Facebook Login added. If not, add it there.

If all your other configurations are in place. It works perfect after that.

This is the issue from Facebook. Confirmed by Facebook Team.

enter image description here

We will Expected Resolution: within 3 days

The problem for me is really with the hash key, It's not valid.

I had exactly the same problem and it was very hard to diagnose. The reason is that Facebook doesn't check the hash key at first login and it seems that the key is correct, but indeed it's not. Second, the error message is simply an idiocracy. Third is the resolution: try the following link, it helped me.

Better instructions to generate a valid hash key

I refer this,

https://developers.facebook.com/docs/android/getting-started

or just add below code in onCreate() method, which will return key hash.

 // 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) {


}

Add above code to retrieve key,that key you can store

https://developers.facebook.com/docs/facebook-login/android

here. Now It will work.

It worked for me, hope will work for you too.

OR

This command may not give you latest keyhash.

keytool -exportcert -alias YOUR_RELEASE_KEY_ALIAS -keystore YOUR_RELEASE_KEY_PATH | openssl sha1 -binary | openssl base64

To get latest or active keyhash from android studio search 'hash' in your android studio's Logcat or android monitor while app is running and throwing above error. You will get different keyhash which is active. After pasting this searched keyhash in your console setting you may log be able to your app.

For me, this exact error was due to invalid permission strings. Happened on iOS and Android.

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!

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:

  1. Go to Release Management here

  2. Select Release Management → App Signing

  3. You can see SHA1 key in hex format App signing certificate.

  4. Copy the SHA1 in hex format and convert it in to base64 format, you can use this link do that without the SHA1: part of the hex.

  5. Go to Facebook developer console and add the key (after convert to base 64) in the 

    settings → basic → key hashes

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 had the same problem today on my sites and then realised that I was using the old default_graph_version = v3.2. I've changed it to the latest:

default_graph_version = v4.0

Now everything works again. Give it a try.

ANSWER

Just throwing this out there for people still experiencing this issue. The hash I created through the keytool was somehow incorrect. I fixed it by doing the following:

If you already uploaded your app to the playstore and enabled "app signing by Google Play" there is a solution (at least this worked for me):

  1. Login into the Google Play Console
  2. Click on the app you want the hash from
  3. Now, open the navigation on the left hand side
  4. Under Release click Setup > App integrity Navigation drawer in the Google Play Console
  5. Under App signing certificate copy the SHA-1 certificate fingerprint
  6. Go to http://tomeko.net/online_tools/hex_to_base64.php
  7. Paste the SHA-1 in the first field
  8. Copy the text in input field under Output (base64)
  9. Now open developer.facebook.com/apps
  10. Navigate to the dashboard of your app (My Apps > Your App Name)
  11. On the left side navigate to Settings > Basic
  12. Paste the Base64 text here under Key Hashes enter image description here

That should fix the issue.


UPDATE

The steps above should still fully work.

But if you do not want to paste your key on that website, here is an alternative to step 6,7,8 below:

here's a oneliner Node.js command to do the same:

node -e 'console.log(Buffer.from(process.argv[1].split(":").map(hex => parseInt(hex, 16))).toString("base64"))' '5E:8F:16:06:2E:A3:CD:2C:4A:0D:54:78:76:BA:A6:F3:8C:AB:F6:25'

credits: mifi


The issue for me (at the time of writing this) was when adding hash directly in Facebook Login -> Settings page. For some strange reason it does not save it correctly.

I fixed this with going to Quickstart and adding hashes in one of the steps and hitting Save. (fix will probably be obsolete when they fix their web page)

I did not have an issue with the tool, it generated correct hash. People with wrong Play store hashes probably have Play store signing enabled or entered wrong credentials.

I resolved the same issue by replacing the key hash,

How to generate the key hash for release. Open Chrome browser console to convert a hex map key to base64

Copy SHA1 key from google play console.

> btoa('a1:43:d4:27:c8:04:rr:fr:2g:3b:tg:b5:et:c1:4a:1t:fr:f5:54:5f'.split(':').map(hc => String.fromCharCode(parseInt(hc, 16))).join(''))
< "g5fGIBgB6noFO9ur78BdEr73KG6="
  1. Generate .apk file
  2. open a terminal where .apk file exists
  3. to keep in your mind that you have to generate two separate SHA1 keys for release and debug. e-g just run following command with debug.apk and release.apk
  4. run keytool -list -printcert -jarfile yourapkname.apk
  5. you will get

MD5: 00:00:A0:00:00:00:72:00:00:B9:00:00:00:3D:00:00

SHA1: 00:00:94:00:67:00:FA:00:4E:00:CE:80:00:1A:00:00:00:00:00:00

SHA256: 00:00:00:34:00:00:00:00:00:00:00:00:00:00:00:00:56:00:F5:00:00:49:00:4A:00:00:00:00:00:00:00:00

  1. copy SHA1 open http://tomeko.net/online_tools/hex_to_base64.php
  2. past in Hex string your Key Hash will be in Output (base64)
  3. copy your Key Hash and add in your App setting on developers.facebook.com

if you setup the key hash correctly, it may be related to the facebook app. This is occurring only on Android if the facebook application is installed on device! (to make sure, just uninstall the fb app and try again.) one solution is to authenticating using web and ignore the native fb app.

In our case, we use expo app and it does not support redirection to the app after login success. We needed to setup the configuration to not open the facebook app but the embedded browser or the phone's browser by specifying the behavior.

Facebook.logInWithReadPermissionsAsync({
permissions: [
"public_profile",
"email",
"user_birthday",
"user_hometown",
"user_location",
],
behavior: "web"
})

Hope it help someone, we've lost many time solving this :)

I was getting this error when signing in from a different account. when i signed in using developer account i recieved this error Facebook Login: "The application has disabled the Oauth client flow for Facebook integration" which was solved by enabling Client Oauth login from facebook developer account->myApp->products-> Facebook Login

  • Hello All, I face this issue from last 2 months..

finally I got the solution.

  • Follow the Steps and Say in last. "Hurrey"

     1. Complete all process of facebook integration in android.
    2. Create your ***Hashkey (SHA1 key)*** from android
    - steps : Go to left of Android studio screen and double click on this selected option.
    

enter image description here

    3. Then select SHA1 key from *"debug"* or *"release"* Variant.
- If you want to do in live app then use *"release"* Varient.
- other wise use *"debug"* Variant's SHA1 Key.
4. Then Open the following link: http://tomeko.net/online_tools/hex_to_base64.php and paste SHA1 key.

enter link description here

    5. Select Output(base64) key which has "=" sign in end of line.
6. Open your `Developer Facebook` site and Select Integrated App
then Go to -> Settings -> Basic -> Key hashes. Add these new key here.

enter image description here

     7. Done Keep Code.