当用户单击我的应用程序中的自定义按钮时,会在用户 facebook 墙上发布内容。我的问题是安装 facebook 应用程序并且用户第一次登录应用程序或用户登录 facebook 应用程序时。什么时候,我尝试注销并使用其他帐户登录并执行我的应用程序。该应用程序发布在第一个帐户的 Facebook 墙上,而不是第二个帐户。如何检查登录 facebook 应用程序的当前用户?
public void onCreateSMWDLoginFBByAccessToken() {
Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
Session session = Session.getActiveSession();
if (session == null) {
session = new Session(ShareFacebookActivity.this);
Session.setActiveSession(session);
}
if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
openSessionForPublish(session);
}
onClickLoginFB();
}
public void openSessionForPublish(Session session) {
Session.OpenRequest openRequest = new Session.OpenRequest(ShareFacebookActivity.this);
if (openRequest != null) {
openRequest.setDefaultAudience(SessionDefaultAudience.FRIENDS);
openRequest.setPermissions(ConstantsFacebook.PERMISSIONS_PUBLISH);
openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
openRequest.setCallback(statusCallback);
session.openForPublish(openRequest);
}
}
private void onClickLoginFB() {
Session session = Session.getActiveSession();
if (!session.isOpened() && !session.isClosed()) {
openSessionForPublish(session);
} else {
Session.openActiveSession(ShareFacebookActivity.this, true, statusCallback);
}
}
public class SessionStatusCallback implements Session.StatusCallback {
@Override
public void call(Session session, SessionState state, Exception exception) {
// REFRESH FACEBOOK STATE
refreshStateSessionFB(session);
}
}
private void refreshStateSessionFB(Session session) {
if (session.isOpened()) {
Request.executeMeRequestAsync(session, statusUserFB);
}
}// end Method
public class SessionGraphUserStatusCallback implements Request.GraphUserCallback {
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
publishContent();
}
}// end OnCompleted
}// end Class