get user facebook permissions

我怕爱的太早我们不能终老 提交于 2019-12-19 11:49:12

问题


I want to add a facebook permission to my users. That is how I do it:

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("email");

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

                Request.newMeRequest(session, new Request.GraphUserCallback() {
                    @Override
                    public void onCompleted(GraphUser user, Response response) {
                        if (user != null) {
                            Toast.makeText(MainActivity.this, user.asMap().get("email").toString(), Toast.LENGTH_LONG).show();
                        }
                    }
                }).executeAsync();
            }
        }
    });

The problem is that I don't want to open a session every time, just if the user don't have this permission. Is there a way to locally know if the user has already approved this permission in my app?


回答1:


use below code

Session session = getActiveSession();
if(session.isOpened)
{
  List<String> permissions = session.getPermissions();
    if(!permissions.contain("email"))
    {
 Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(MainActivity.this,
                            PERMISSIONS);
                    session.requestNewReadPermissions(newPermissionsRequest);

}
}else
{
Session.openActiveSession(this, true,callback);
}


来源:https://stackoverflow.com/questions/18978108/get-user-facebook-permissions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!