简体   繁体   English

更新Facebook android会话权限而无需注销和再次登录

[英]Updating facebook android session permissions without logging out and in again

I am using the Facebook SDK for an Android app which requires 2 permissions additional to the standard one for logging in/out. 我正在使用Android应用程序的Facebook SDK,这需要标准登录权限之外的2个权限。 The two permissions are a read permission: User Groups and a publish permissions: publish. 这两个权限是读取权限:用户组和发布权限:发布。

The problem is that in the latest facebook api requires to ask each permission separately. 问题在于,在最新的facebook api中,需要分别询问每个权限。 Which I am fine with. 我可以的。

The issue is that the session object is not updated with the new permissions after the user confirms them, unless I logout and login into the app again. 问题在于,除非用户注销并再次登录到应用程序,否则在用户确认会话对象后,不会使用新权限更新会话对象。

This would not be an issue if I could ask all permissions at once, but again, not possible anymore. 如果我可以一次询问所有权限,那么这将不是问题,但是再次不可能。

Is there any other way to avoid this? 还有其他方法可以避免这种情况吗?

And yes, I have tried everything in the OnActivityResult , and the permissions in the Session.getActiveSession() object is not updated with the new permissions, even though if I try to do the needed action it works. 是的,我已经尝试了OnActivityResult中的所有操作 ,并且即使我尝试执行所需的操作, Session.getActiveSession()对象中的权限也不会使用新的权限进行更新。

And it's totally unfeasable to ask the user to logout and login of the app after each permission request. 在每个权限请求之后要求用户注销和登录应用程序是完全不可行的。

This is what I have in my OnActivityResult (which works completely fine btw). 这就是我的OnActivityResult中的内容(顺便说一句,它工作得很好)。

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Log.d("RADARE","ON ACTIVITY RESULT CALLED");
    Log.d("RADARE","REQUEST CODE: " + requestCode + " == RESULT CODE: " + resultCode + " == INTENT: " + data.toString());
    if (RESULT_CANCELED == resultCode) {
        Log.d("RADARE", "Canceled");
    }
   Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);



    uiHelper.onActivityResult(requestCode, resultCode, data, new FacebookDialog.Callback() {

        @Override
        public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) {
            Log.e("Activity", String.format("Error: %s", error.toString()));
        }

        @Override
        public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) {
            Log.i("Activity", "Success!");
        }
    });







     Session session = Session.getActiveSession();


     Log.d("RADARE","Session info: TOKEN: " + session.getAccessToken() + " == PERMISSIONS: " + session.getPermissions().toString() + " == STATE: " + session.getState());
     Toast.makeText(this, "You have to logout and login again in order for the service to work.", Toast.LENGTH_LONG).show();

My first idea would be instead of using Session.getPermissions().contains("needed_permission_here") to actually check online for the permission instead of the Session object. 我的第一个想法是,而不是使用Session.getPermissions()。contains(“ needed_permission_here”)来实际在线检查权限,而不是使用Session对象。

Right now it just enters a loop: 现在,它刚刚进入一个循环:

The permissions are checked => permissions is not there => Jumps to facebook app asking for permissions => the user grants it => the app checks again for permission (which are not there even though the user has confirmed them) and jumps to facebook (which of course just replies back with the confirmed permission) and they dance back and forth infinitely. 权限已检查=>权限不存在=>跳转至Facebook应用程序以请求权限=>用户授予它=>应用程序再次检查权限(即使用户已确认权限也不存在)并跳转至Facebook (当然,只有得到确认的许可才能回复),他们会无限地来回跳舞。

Do you have any other ideas than checking the permissions online instead of the object? 除了在线检查权限而不是对象之外,您还有其他想法吗?

Quoting from FB Login Permissions page FB登录权限页面引用

user_groups- Limited Use user_groups-限制使用

This permission is granted to apps building a Facebook-branded client on platforms where Facebook is not already available. 此权限授予在尚不可用Facebook的平台上构建Facebook品牌客户端的应用程序。 For example, Android and iOS apps will not be approved for this permission. 例如,Android和iOS应用程序将不会获得此权限。 In addition, Web, Desktop and TV apps will not be granted this permission 此外,不会授予Web,桌面和电视应用此权限

And for checking if the permissions are granted already 并检查是否已授予权限

    private static final String PERMISSION = "publish_actions";

    <- Whatever read permissions you need ->
            authButton.setReadPermissions(Arrays.asList("email", "user_birthday",
                    "read_stream", "user_friends","read_friendlists "));

    public void call(Session session, SessionState state,
                    Exception exception) {

                    if (session.isOpened()) {

                        List<String> permissions = session.getPermissions();
                        if (!permissions.contains(PERMISSION)) {
                            pendingAnnounce = true;
                            requestPublishPermissions(session);
                            return;
                        }
}

I dont know how much of help this will be to you.. 我不知道这会对您有多大的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Facebook LoginButton没有注销会话 - Facebook LoginButton is not logging out of session Android Facebook SDK注销并清除当前用户会话 - Android Facebook SDK Logging out & Clearing the Current User Session Facebook SDK一次又一次地要求权限,就像在android中循环运行一样 - Facebook SDK asking for permissions again and again like running in a loop in android Android Facebook SDK,请求发布权限“ manage_pages”未更新会话权限列表 - Android Facebook SDK, requesting publish permission “manage_pages” isn't updating session permissions list Android 本地更新Parse User信息无需注销重新登录 - Updating Parse User information locally without having to log out and log in again in Android 退出Android后无法登录Facebook登录 - Facebook login not logging in after log out Android 从已连接Facebook的Android应用注销 - Logging out from Facebook connected Android app 适用于Android的Facebook:会话尝试请求会话的新权限 - Facebook for Android: Session an attempt was made to request new permissions for a session Android Facebook SDK“具有待处理请求的会话的新权限”错误 - Android Facebook SDK “new permissions for a session that has pending request” error Android 应用程序权限记录 - Android Application Permissions Logging
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM