Facebook Android SDK LoginManager Callback永远不会被调用

时间:2015-11-09 01:47:55

标签: android facebook-android-sdk

我在Android应用中使用以下代码段来要求用户登录Facebook

public class FacebookLoginActivity extends AppCompatActivity {
    private CallbackManager callbackManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FacebookSdk.sdkInitialize(this.getApplicationContext());
        initCallback();
        LoginManager.getInstance().logInWithReadPermissions(this, FacebookUtils.requiredPermissions);
    }

    private void initCallback() {
        callbackManager = CallbackManager.Factory.create();
        LoginManager.getInstance().registerCallback(callbackManager,
                new FacebookCallback<LoginResult>() {
                    @Override
                    public void onSuccess(LoginResult loginResult) {
                       AccessToken.setCurrentAccessToken(loginResult.getAccessToken());

                    @Override
                    public void onCancel() {

                    }

                    @Override
                    public void onError(FacebookException exception) {

                    }

                }
        );
    }

    @Override
    protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        callbackManager.onActivityResult(requestCode, resultCode, data);
    }
}

但是,回调中定义的方法永远不会被调用。有人可以帮帮我吗?

0 个答案:

没有答案