0

嗨,我尝试在我的应用中添加 public_stream 权限。我在控制台中打印了我的会话信息,并观察到当我添加公共权限时,我的会话状态为 CLOSED_LOGIN_FAILED,当我删除此权限时,会话状态为 OPENING,并且我设置了其他读取权限。

这是我的代码:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    uiHelper = new UiLifecycleHelper(getActivity(), callback);
    uiHelper.onCreate(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.facebook_login_view, container,
            false);

    facebookButton = (LoginButton) view.findViewById(R.id.facebookAuth);
    facebookButton.setFragment(LoginAuthFragment.this);
    //facebookButton.setReadPermissions("email", "user_birthday");
    facebookButton.setPublishPermissions("publish_stream", "email", "user_birthday");

    return view;
}
private Session.StatusCallback callback = new Session.StatusCallback() {
    @Override
    public void call(Session session, SessionState state, Exception exception) {
            onSessionStateChange(session, state, exception);
    }
};

private void onSessionStateChange(Session session, SessionState state, Exception exception) {
   System.out.println(session);
   System.out.println("Access token: "+session.getAccessToken());

 final User u = new User();

        if(session.isOpened()){
            System.out.println("OK");
            final String subscribe;
            if(receiveMail.isChecked()){
                subscribe = "1";
            }else{
                subscribe = "0";
            }

            final String access_token=session.getAccessToken();

            Request request = Request.newMeRequest(session, new Request.GraphUserCallback() {

                @Override
                public void onCompleted(GraphUser user, Response response) {
                            if (user != null) {

                                String firstName = user.getFirstName();
                                String lastName = user.getLastName();
                                String userName = "fb_user_"+user.getId();
                                String facebook_id = user.getId();
                                String birthday = user.getBirthday();
                                String email = user.asMap().get("email")
                                        .toString();
                                String response1 = u.checkFacebookUser(
                                        userName, facebook_id, access_token,
                                        birthday, email, subscribe, firstName, lastName);

                                if (response1.equals("GREEN")) {
                                    prefs.setTokenData(u.getToken(),
                                            u.getCreatedAt(), u.getExpires());
                                    Intent loggedIn = new Intent(getActivity().getApplicationContext(),
                                            MainActivity.class);
                                    startActivity(loggedIn);
                                    getActivity().finish();
                                } else if (response1.equals("RED")) {
                                    Toast.makeText(
                                            getActivity()
                                                    .getApplicationContext(),
                                            "Unknown error", Toast.LENGTH_LONG)
                                            .show();
                                } 

                            }

                }
            });
            Request.executeBatchAsync(request);
        }
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    uiHelper.onActivityResult(requestCode, resultCode, data);
}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    uiHelper.onSaveInstanceState(outState);
}

@Override
public void onResume() {
    super.onResume();
    Session session = Session.getActiveSession();

    if (session != null &&
            (session.isOpened() || session.isClosed()) ) {
        onSessionStateChange(session, session.getState(), null);
    }

    uiHelper.onResume();
}

@Override
public void onPause() {
    super.onPause();
    uiHelper.onPause();
}

@Override
public void onDestroy() {
    super.onDestroy();
    uiHelper.onDestroy();
}

这是我添加 publish_stream 权限时的会话

{会话状态:CLOSED_LOGIN_FAILED,令牌:{AccessToken 令牌:ACCESS_TOKEN_REMOVED 权限:[]},appId:593058290740634}

这是我没有 publish_stream 权限的会话:

{会话状态:OPENED,令牌:{AccessToken 令牌:ACCESS_TOKEN_REMOVED 权限:[email,user_birthday,user_friends,basic_info]},appId:593058290740634}

4

1 回答 1

1

如果没有首先获得“basic_info”(这是一种读取权限),您就无法请求发布权限。

正确的做法是首先向用户请求 email 和 user_birthday 权限,当您准备好发布时(通常在一些用户交互之后),然后请求 publish_stream 权限。

于 2013-10-28T20:08:45.260 回答