0

我想为我的用户添加 facebook 权限。我就是这样做的:

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

问题是我不想每次都打开一个会话,只要用户没有这个权限。有没有办法在本地知道用户是否已经在我的应用中批准了这个权限?

4

1 回答 1

0

使用下面的代码

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);
}
于 2013-09-24T11:30:06.163 回答