2

我正在将 facebook 集成到我的 android 应用程序中,当用户第一次登录时,我正在使用我的 requestFacebookPermissions(session) 方法请求 publish_actions 权限。但是每当我调用此方法时,它都会给我以下异常...

java.lang.UnsupportedOperationException: Session: an attempt was made to request new permissions for a session that has a pending request. 

我没有任何其他待处理的请求,可能是其他一些内部请求,但是我如何在不获得此异常的情况下请求权限?如果我必须等到其他请求完成也没关系,但我不知道如何获取挂起的请求是否完成。

private void requestFacebookPermissions(Session session) {

        if (session != null && session.getState().isOpened()) {
            List<String> permissions = session.getPermissions();

            Log.i("Facebook", "Permissions Count: " + permissions.size());

            for (String string : permissions) {
                Log.i("FacebookPermissions", string);
            }

            if (!permissions.containsAll(PERMISSIONS)) {
                try {
                    session.requestNewPublishPermissions(new Session.NewPermissionsRequest(FacebookActivity.this, PERMISSIONS));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else {
            return;
        }
    }
4

1 回答 1

1

我在登录后请求发布权限

这是我的代码

public class FacebookAccount extends FragmentActivity {
    private UserSettingsFragment userSettingsFragment;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.facebook_login);

        FragmentManager fragmentManager = getSupportFragmentManager();
        userSettingsFragment = (UserSettingsFragment) fragmentManager
                .findFragmentById(R.id.login_fragment);

        userSettingsFragment.setReadPermissions(Utility.READ_PERMISSIONS);

        userSettingsFragment
                .setSessionStatusCallback(new Session.StatusCallback() {
                    @Override
                    public void call(Session session, SessionState state,
                            Exception exception) {
                        if (state == SessionState.OPENED
                                && !session.getPermissions().containsAll(
                                        Utility.PUBLISH_PERMISSIONS)) {
                            session.requestNewPublishPermissions(new Session.NewPermissionsRequest(
                                    FacebookAccount.this,
                                    Utility.PUBLISH_PERMISSIONS));
                        }
                        if (session.isOpened()
                                && state == SessionState.OPENED_TOKEN_UPDATED) {
                            ....Save session access token
                        }
                    }
                });
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (userSettingsFragment != null)
            userSettingsFragment
                    .onActivityResult(requestCode, resultCode, data);
        super.onActivityResult(requestCode, resultCode, data);
    }

}
于 2013-06-22T02:21:38.803 回答