3

我在我的应用程序中使用 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");    

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

任何帮助将不胜感激提前感谢

4

3 回答 3

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

我认为这个问题是“email”、“user_birthday”、“user_location”:是 session.requestNewReadPermissions(...);

于 2013-08-28T13:45:17.323 回答
0

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

于 2015-01-07T10:30:45.173 回答
0

我在安装 Facebook 应用程序时遇到了同样的问题。我认为默认情况下用于验证会话的 SSO(单一登录)是导致“循环”的原因。

要解决此问题,请在您newPermissionRequest的标志中添加以抑制 SSO:

Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(context, PERMISSIONS);
newPermissionsRequest.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);
session.requestNewPublishPermissions(newPermissionsRequest);
于 2015-01-16T18:55:12.417 回答