3

嗨,我正在使用新的 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); 处,编译器总是说错误,例如:尝试为具有待处理请求的会话请求新权限。

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

4

1 回答 1

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/

于 2013-01-17T01:00:29.153 回答