Facebook SDK一次又一次地要求权限,就像在android中循环运行一样

时间:2013-08-20 07:41:08

标签: android facebook facebook-android-sdk

我在我的应用中使用Facebook SDK(最新版本)。我只想从登录用户获取一般数据,如姓名,出生日期,地点,性别等,并且只想相应地填写详细信息。但问题是它一次又一次地无限显示权限对话框,即使我按下“确认”或“取消”进入应用程序权限对话框,它也会一次又一次地显示该权限对话框。我不明白这是怎么回事。

我的登录功能是这样的: -

    Session.openActiveSession(context, true, new Session.StatusCallback() {

        @Override
        public void call(final Session session, SessionState state, Exception exception) {
            // TODO Auto-generated method stub
            if(session.isOpened())
            {
                Toast.makeText(context, "Please Wait", 1).show();
                List<String> permissions = session.getPermissions();

                if (!isSubsetOf(PERMISSIONS, permissions)) {
                    pendingPublishReauthorization = true;
                    Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(context, PERMISSIONS);
                    session.requestNewPublishPermissions(newPermissionsRequest);
                }

                Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {

                    @Override
                    public void onCompleted(GraphUser user, Response response) {
                        // TODO Auto-generated method stub
                        if(user!=null)
                        {

                            try{
                                Log.d("", "Fb responcse == "+response.toString());
                                Log.d("", "FbUser >> "+ user.toString());
                                fbUserid=user.getId();
                                fbAccessToken=session.getAccessToken();
                                Log.i("User Name ", "FbName : "+user.getName());
                                Log.i("User Id ", "FbId : "+user.getId());
                                Log.i("User Id ", "FbLocation : "+user.getLocation().toString());

                                Log.i("User Id ", "FbEmailId : "+user.getLink());
                                Log.i("User Id ", "FbDob : "+user.getBirthday());

                                Log.i("User Id ", "FbGender : "+user.asMap().get("gender").toString());
                                Log.i("User Id ", "FbEmail : "+user.getProperty("email").toString());
                                //Log.i("User Id ", "FbCity : "+user.getLocation().getCity().toString());
                                //Log.i("User Id ", "FbState : "+user.getLocation().getState().toString());
                                Log.i("User Access Token ", "FbAccess Token : "+session.getAccessToken());
                                pBar.setVisibility(View.INVISIBLE);

                                String name = user.getName();
                                String dob = user.getBirthday();
                                String gender = user.asMap().get("gender").toString();
                                String email =user.getProperty("email").toString();
                                String city = user.getLocation().getProperty("name").toString();
                                String url="http://graph.facebook.com/"+user.getId()+"/picture?type=large";
                                setText(name, dob, email, city, "","",url);
                            }catch(Exception ex){
                                ex.printStackTrace();
                            }


                        }

                        else{
                            pBar.setVisibility(View.INVISIBLE);
                            Log.i("ELSE", "ELSE");
                        }
                    }


                });

            }


        }


    });

此外,我使用此代码段来获取这些详细信息的权限: -

List<String> PERMISSIONS = Arrays.asList("publish_actions","email","user_birthday","user_location");    

请帮我解决这个问题,因为它一次又一次地向我显示权限对话框。

提前感谢任何帮助

3 个答案:

答案 0 :(得分:1)

试试这个:

Session.openActiveSession(this, true, new Session.StatusCallback() {
        @Override
        public void call(Session session, SessionState state, Exception exception) {
            if (session.isOpened())
            {
                List<String> PERMISSIONS = Arrays.asList("publish_actions");

                if (!session.getPermissions().containsAll(PERMISSIONS))
                {
                    Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(ActivityRegistration.this, PERMISSIONS);
                    session.requestNewPublishPermissions(newPermissionsRequest);
                }

                Request.newMeRequest(session, new Request.GraphUserCallback() {
                    @Override
                    public void onCompleted(GraphUser user, Response response) {
                        if (user != null) {
                            Log.i("Facebook Welcome " + user.getName());
                            compileWithFacebookInfo(user);
                        }
                    }
                }).executeAsync();
            }
        }
    });

我认为问题是“电子邮件”,“user_birthday”,“user_location”:是     session.requestNewReadPermissions(...);

答案 1 :(得分:0)

我们也遇到了这个问题。解决方案是检查权限名称。如果其中一个权限名称错误(例如,被删除),则session.requestNewPublishPermissions(..)会一次又一次地调用Session.StatusCallback()的回调方法call()。

答案 2 :(得分:0)

安装Facebook应用程序时遇到同样的问题。我认为默认情况下使用SSO(Sigle Sign On)来验证会话是导致#34;循环&#34;。

要解决此问题,请在newPermissionRequest标记处添加以禁止SSO:

Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(context, PERMISSIONS);
newPermissionsRequest.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);
session.requestNewPublishPermissions(newPermissionsRequest);