Pregunta

I am trying to login to facebook from my app and get user details. I am using my own custom button instead of Loginbutton of facebook sdk v3.5. My issue is, on clicking the button, the ask permission dialog box, that is supposed to appear for the user to agree for permissions to access details such as Friend list, email etc not coming. Instead it shows loading symbol for few seconds and is directly going to the next activity. Below is the code I am using. I want the permissions dialog box appear when user clicks login button. below is my code

fbLogin.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
             loginToFb();
        }
    });

}

private void loginToFb() {
    Session.openActiveSession(this, true, new Session.StatusCallback() {

        // callback when session changes state
        @Override
        public void call(Session session, SessionState state,
                Exception exception) {
            if (session.isOpened()) {
                final Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(
                        LandingPageActivity.this, Arrays.asList("user_location", "user_birthday", "user_likes", "email"));
                session.requestNewReadPermissions(newPermissionsRequest);

                // make request to the /me API
                Request request = Request.newMeRequest(session,
                        new Request.GraphUserCallback() {

                            // callback after Graph API response with user
                            // object
                            @Override
                            public void onCompleted(GraphUser user,
                                    Response response) {
                                if (user != null) {
                                    fetchUserFbDetails(user);
                                    Intent intent = new Intent(getApplicationContext(),
                                            SignUpActivity.class);

                                                startActivity(intent);
                                            finish();
                                    }
                                }
                            }
                        });
                Request.executeBatchAsync(request);
            }
        }
    });
}
¿Fue útil?

Solución

Try This..

private void loginToFb() {
    Session.openActiveSession(this, true, new Session.StatusCallback() {

        // callback when session changes state
        @Override
        public void call(Session session, SessionState state,
                Exception exception) {
            if (session.isOpened()) {
                try
                        {
                            Session.OpenRequest request = new Session.OpenRequest(this);
                            request.setPermissions(Arrays.asList("user_location", "user_birthday", "user_likes", "email"));
                        }
                    catch (Exception e)
                        {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }

                // make request to the /me API
                Request request = Request.newMeRequest(session,
                        new Request.GraphUserCallback() {

                            // callback after Graph API response with user
                            // object
                            @Override
                            public void onCompleted(GraphUser user,
                                    Response response) {
                                if (user != null) {
                                    fetchUserFbDetails(user);
                                    Intent intent = new Intent(getApplicationContext(),
                                            SignUpActivity.class);

                                                startActivity(intent);
                                            finish();
                                    }
                                }
                            }
                        });
                Request.executeBatchAsync(request);
            }
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top