回复Facebook requestNewPublishPermissions - Android

时间:2013-06-14 16:34:07

标签: java android facebook facebook-graph-api

我正在尝试从我的Android应用程序中获取用户的发布权限,但我取得了成功但是当我获得权限时,我想要一个回调来告诉我这一点。这是我的代码:

private void requestPublishPermissions(Session session) {
    Log.d("", "Requesting Publish Permissions...");
    if (session != null) {
        List<String> publishPermissions = Arrays.asList("publish_actions", "publish_stream");
        final int REAUTH_ACTIVITY_CODE = 100;
        Session.NewPermissionsRequest reauthRequest = new Session.NewPermissionsRequest(this, publishPermissions).setRequestCode(REAUTH_ACTIVITY_CODE);
        reauthRequest.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);
        session.requestNewPublishPermissions(reauthRequest);
    }
}

session.requestNewPublishPermissions(reauthRequest);是否有回调或某些东西告诉我该权限已被接受?

感谢任何输入

3 个答案:

答案 0 :(得分:2)

我不知道该请求的回调,但有一种简单的方法可以获得所需的结果。

只需为onSessionStateChanged()回调添加条件。如果您使用session.getPermissions().contains("xxx")检查该方法的权限,则应该可以在那里办理登机手续。只要会话状态发生变化,它就会调用该方法,我认为这包括更新权限。

答案 1 :(得分:0)

您可以手动将回调添加到FB会话。

Session.getActiveSession().addCallback(new StatusCallback() {

            @Override
            public void call(Session session, SessionState state, Exception exception) {
                if (session.getPermissions().contains("publish_actions")) {
                    //do stuff


                }
            }
        });

答案 2 :(得分:0)

StatusCallback添加到您的会话中。

private Session.StatusCallback statusCallback = new SessionStatusCallback();

private class SessionStatusCallback implements Session.StatusCallback {
    @Override
    public void call(final Session session, SessionState state, Exception exception) {
        if (session.isOpened()) {
            switch (state) {
                case OPENED_TOKEN_UPDATED:
                    // Returns here after you request publish permissions
                    // So call your publishing actions here
                    break;
            }
        }
    }
}

实施将onActivityResult()粘合在一起的@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data); }

{{1}}