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