尝试为具有挂起请求的会话请求新权限

时间:2012-12-26 10:19:38

标签: android facebook permissions

嗨我用facebook SDK 3.0开发Android应用程序。

我试图在用户登录后请求'publish_stream'权限。 所以,在onSessionStateChange()中,我把我的代码请求'publsh_stream'权限,但它不起作用。

这是我的代码:

private void onSessionStateChange(Session session, SessionState state, Exception exception) {

    if (state.isOpened()) {

        if (pendingPublishReauthorization &&   state.equals(SessionState.OPENED_TOKEN_UPDATED)) {
            pendingPublishReauthorization = false;
            publishFeed(userName);
        }

        m_pd.show();
        Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
            @Override
            public void onCompleted(GraphUser user, Response response) {
                if (user != null) {

                    String username=buildUserInfoDisplay(user);
                    userName=username;
                    saveAccount(username, "facebook");

                    Log.d(com.dress.folio.Constants.FACEBOOK_TAG, "login success");
                    //publishFeed(userName);
                    m_pd.dismiss();

                    h.postDelayed(irun, 1000);
                    Activity GetActivity=getActivity();
                    if(GetActivity != null) GetActivity.finish();

                }
            }
        });


        List<String> permissions = session.getPermissions();
        if (!isSubsetOf(PERMISSIONS, permissions) ) {

            pendingPublishReauthorization = true;
            //if(state == SessionState.OPENED_TOKEN_UPDATED) {
                Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(this, PERMISSIONS);
                session.requestNewPublishPermissions(newPermissionsRequest);
            //}

        }



    } else if (state.isClosed()) {
        Log.i(com.dress.folio.Constants.FACEBOOK_TAG, "Logged out..." + exception);
    }
}

在session.requestNewPublishPermissions(newPermissionsRequest);行,编译器总是说错误:尝试为具有待处理请求的会话请求新权限。

如何在用户facekbook SSO登录我的应用程序后立即请求publish_stream。??

1 个答案:

答案 0 :(得分:11)

我只是面对同样的问题,onActivityResult方法被覆盖了。 所以请务必致电:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
   Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);

}

这个方法应该在之后调用你的回调。 更多信息(第6节):https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/