0

I created a simple facebook login

It can correctly display login popup and ask me to grant permission to my app

But it does not run any callback when I logged-in facebook

No success, no cancel, even no error

Why the login button is not work?

CallbackManager callbackManager;
private AccessToken accessToken;
@Override
protected void onCreate(Bundle savedInstanceState) {
    FacebookSdk.sdkInitialize(getApplicationContext());
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_facebook);

    callbackManager = CallbackManager.Factory.create();

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

    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {

            accessToken = loginResult.getAccessToken();

            Log.v("FB", "access token got.");

            GraphRequest request = GraphRequest.newMeRequest(
                    accessToken,
                    new GraphRequest.GraphJSONObjectCallback() {

                        @Override
                        public void onCompleted(JSONObject object, GraphResponse response) {

                            Log.v("FB", "complete");
                            Log.v("FB", object.optString("name"));
                            Log.v("FB", object.optString("link"));
                            Log.v("FB", object.optString("id"));

                        }
                    });

            Bundle parameters = new Bundle();
            parameters.putString("fields", "id,name,link");
            request.setParameters(parameters);
            request.executeAsync();
        }

        @Override
        public void onCancel() {
            Log.v("FB", "CANCEL");
        }

        @Override
        public void onError(FacebookException exception) {
            Log.v("FB", exception.toString());
        }
    });
}
CL So
  • 3,647
  • 10
  • 51
  • 95
  • Follow This example http://javatechig.com/android/using-facebook-sdk-in-android-example – Sameer Donga Sep 16 '15 at 06:00
  • 1
    That link actually refers to v3 of the SDK, whereas v4.x of the SDK has made significant changes. Did you override the onActivityResult method of your activity or fragment? – Ming Li Sep 16 '15 at 22:19
  • 2
    http://stackoverflow.com/questions/31327897/custom-facebook-login-button-android/31332928#31332928 Check here.may be you can get solution. – Harvi Sirja Sep 17 '15 at 04:43
  • Yes, that is right, this program is missing onActivityResult, now the program is work – CL So Sep 17 '15 at 05:43

0 Answers0