facebook login fails: {Session state:CLOSED_LOGIN_FAILED, token:{AccessToken token:ACCESS_TOKEN_REMOVED permissions:[]}, appId:131***64547}

我与影子孤独终老i 提交于 2019-12-04 21:50:15

check your Manifest.xml

 <meta-data android:value="@string/facebook_app_id" android:name="com.facebook.sdk.ApplicationId"/>

and your strings.xml have

  <string name="facebook_app_id">131390430364547</string>

verify the app_id is the same in your facebook app configuration and set the "yourApp.mainactivity" in the Class field

is it the debbug app or released app? the hash code is diferent for each one

Edited *

for verify the status of the session

private Session.StatusCallback callback = new Session.StatusCallback() {

    @Override
    public void call(Session session, SessionState state, Exception exception) {
        onSessionStateChange(session, state, exception);
        if (session.isOpened()) {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
          Log.e("user", "session established");
            Request.newMeRequest(session, new Request.GraphUserCallback() {

                @Override
                public void onCompleted(GraphUser user, Response response) {
                    if (user != null) {
                    Log.e("user", "loged user");
                        buildUserInfoDisplay(user);
                    }
                }
            }).executeAsync();
        }
        else{
          Log.e("user", "session not established");
        }
    }
    private void onSessionStateChange(Session session, SessionState state,
                                      Exception exception) {

    }
};

and in the on create method to use the login button

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
            .permitAll().build();

        StrictMode.setThreadPolicy(policy);
        uiHelper = new UiLifecycleHelper(this, callback);
        uiHelper.onCreate(savedInstanceState);
        setContentView(R.layout.login);

        buttonLoginLogout = (LoginButton)findViewById(R.id.authButton);
        buttonLoginLogout.setReadPermissions(Arrays.asList("user_status"));

    }

}

also need to manage the ui status in al lifecycle methods

public void onResume() {
    super.onResume();
    uiHelper.onResume();
}
 public void onPause() {
    super.onPause();
    uiHelper.onPause();
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    uiHelper.onActivityResult(requestCode, resultCode, data);
}

@Override
public void onDestroy() {
    super.onDestroy();
    uiHelper.onDestroy();
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    uiHelper.onSaveInstanceState(outState);
}

I have an app with this login exactly as i posted it, it wors good, facebook developer console is tracking the sessions of users. Try it !

There could be many possible reasons:

  1. Wrong key hash. Generate one from the code provided by facebook:

    PackageInfo info = getPackageManager().getPackageInfo("<your_package_name>",  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));
    }
    

    Make sure to replace "<your_package_name>" with your corresponding package name. Look at logcat and grab the keyhash and enter it in your facebook app settings.

  2. Open the Facebook native app and make sure you are logged in properly and can access content. If you have incorrect credentials entered in the Facebook native app (perhaps you recently changed your password) then the Facebook SDK will repeatedly try to do an SSO using the native app and report back CLOSED_LOGIN_FAILED.

  3. If you are using the Facebook application in the sandbox mode, make sure the account you are using is in the list of authorized admins or developers.

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