其他分享
首页 > 其他分享> > android-获取用户facebook权限

android-获取用户facebook权限

作者:互联网

我想向我的用户添加一个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();
            }
        }
    });

问题是,我不想每次都打开会话,即使用户没有此权限也是如此.
有没有办法本地知道用户是否已经在我的应用程序中批准了此权限?

解决方法:

使用以下代码

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

标签:android,facebook,facebook-android-sdk
来源: https://codeday.me/bug/20191010/1885828.html