FacebookCallback没有被执行

时间:2015-11-24 22:10:51

标签: android facebook android-studio

我有一个应用程序,我在其中实现了facebook登录,这是我上次检查时工作的。出于某种原因,现在,在我点击按钮后没有任何反应。

我的onCreate()

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getActivity());
    mCallbackManager = CallbackManager.Factory.create();
}

我的loginButton

loginButton = (LoginButton) view.findViewById(R.id.login_button);

    loginButton.setReadPermissions("user_friends");

    loginButton.setFragment(this);

    loginButton.registerCallback(mCallbackManager, mFacebookCallback);

我的onActivityResult

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Log.d("askj","Callback called with requestCode "+requestCode+" + resultCode "+resultCode);
    mCallbackManager.onActivityResult(requestCode, resultCode, data);
}

我的mFacebookCallback

 private FacebookCallback<LoginResult> mFacebookCallback = new FacebookCallback<LoginResult>() {
    @Override
    public void onSuccess(LoginResult loginResult) {
        Log.d("askj", "onSuccess");
        AccessToken accessToken = loginResult.getAccessToken();
        Profile profile = Profile.getCurrentProfile();
        Log.d("askj", "profile " + profile.toString());
        if (profile != null) {
            Intent upanel = new Intent(getActivity(), AfterLogin.class);
            upanel.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(upanel);
        }
    }
    @Override
    public void onCancel() {
        Log.d("askj", "onCancel");
    }

    @Override
    public void onError(FacebookException e) {
        Log.d("askj", "onError " + e);
    }
};

这是点击按钮后在logCat中打印的内容:

Callback called with requestCode 129742 + resultCode -1

我无法从控制台中的mFacebookCallback获取任何内容。

编辑:如何向此回调添加特定的requestCode?

Edit2:对于遇到此问题的任何人,我通过删除loginButton.setFragment(this);解决了这个问题。我仍然有How can I add a specific requestCode to this callback ?

这个问题

0 个答案:

没有答案