Facebook android sdk登录权限问题

时间:2013-10-24 06:58:29

标签: android facebook user-permissions android-facebook facebook-sdk-3.0

我正在尝试从我的应用中登录facebook并获取用户详细信息。我使用自己的自定义按钮而不是facebook sdk v3.5的Loginbutton。我的问题是,在单击按钮时,会出现“请求权限”对话框,该对话框应该显示给用户同意访问详细信息(如朋友列表,电子邮件等)的权限。相反,它显示加载符号几秒钟,并直接进入下一个活动。以下是我正在使用的代码。我想在用户单击登录按钮时出现权限对话框。下面是我的代码

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);
            }
        }
    });
}

1 个答案:

答案 0 :(得分:1)

试试这个..

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);
            }