在墙上发布文字:用户未授权应用程序在android中执行此操作facebook

时间:2014-06-25 08:14:28

标签: android facebook facebook-graph-api

我知道这个问题之前已被多次询问过。但是这些答案都没有对我有用。当我登录不同的用户时,显示错误。如果使用此应用程序的凭据管理员登录,在墙上发布工作正常。请尝试解决此问题。

这是我的代码:

if(isFB){//调用FB登录

        Session session = new Session(this);
        Session.setActiveSession(session);

        Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);

        Session.StatusCallback statusCallback = new Session.StatusCallback() {
            @Override
            public void call(Session session, SessionState state,
                    Exception exception) {
                String message = "Facebook session status changed - "
                        + session.getState() + " - Exception: " + exception;
                // Toast.makeText(FacebookShareActivity.this, message,
                // Toast.LENGTH_SHORT).show();
                Log.w("Facebook test", message);

                if (session.isOpened()
                        || session.getPermissions().contains(
                                "publish_actions")) {
                    publishToWall();
                } else if (session.isOpened()) {
                    OpenRequest open = new OpenRequest(
                    RegisterActivity.this).setCallback(this);
                    List<String> permission = new ArrayList<String>();
                    permission.add("publish_actions");
                    open.setPermissions(permission);
                    Log.w("Facebook test", "Open for publish");
                    session.openForPublish(open);
                }
            }
        };

        if (!session.isOpened() && !session.isClosed()
                && session.getState() != SessionState.OPENING) {
            session.openForRead(new Session.OpenRequest(this)
                    .setCallback(statusCallback));
        } else {
            Log.w("Facebook test", "Open active session");
            Session.openActiveSession(this, true, statusCallback);
        }
    }
}

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

    Session.getActiveSession().onActivityResult(this, requestCode,
            resultCode, data);
}
void publishToWall() {
    Session session = Session.getActiveSession();

    Bundle postParams = new Bundle();
    postParams.putString("message", "hi");

    Request request = new Request(Session.getActiveSession(), "me/feed",
            postParams, HttpMethod.POST, callback);

    RequestAsyncTask task = new RequestAsyncTask(request);
    task.execute();
}

1 个答案:

答案 0 :(得分:0)

v2.0起,public_profileemailuser_friends以外的权限必须提交给Facebook审核。批准后,只有developer / tester / admin以外的用户才能使用其功能。

See here获取更多有关登录提交的详细信息。

此外,在与其他用户进行测试之前,请确保将您的应用直播 -

enter image description here