我正在使用最新的 android SDK。对话框已打开,但在输入凭据后对话框正在关闭并且状态不会改变。
private StatusCallback statusCallback = new StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) // call just one time and state is "opening"
authWithToken("facebook", session.getAccessToken());
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new View(this));
//setVisible(false);
Settings.addLoggingBehavior(LoggingBehavior.CACHE);
Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
//Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_RAW_RESPONSES);
//Settings.addLoggingBehavior(LoggingBehavior.REQUESTS);
Session session = Session.getActiveSession();
if (session == null) {
session = new Session.Builder(this).build();
Session.setActiveSession(session);
}
if (!session.isOpened()) {
Session.OpenRequest openRequest = new Session.OpenRequest(this);
openRequest.setPermissions(permissions);
openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
openRequest.setCallback(statusCallback);
session.openForPublish(openRequest); //here dialog is opened, user is able to enter credentials
}
if (session != null && session.isOpened()) {
if (!hasEmailPermission()) {
NewPermissionsRequest request = new NewPermissionsRequest(this, permissions);
request.setCallback(statusCallback);
request.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
session.requestNewReadPermissions(request);
}
}
if (session != null && session.isOpened())
authWithToken("facebook", session.getAccessToken());
}
private boolean hasEmailPermission() {
Session session = Session.getActiveSession();
return session != null && session.getPermissions().containsAll(permissions);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
//never call this method
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
我通过 facebook 官方“入门”文档完成了所有工作
Android Facebook SDK3.0,会话状态OPENING
不起作用,因为 Facebook 身份验证对话框从不调用 onActivityResult()
未安装 Facebook 应用程序。
更新:
我检查了。session.openForPublish(openRequest);
关闭我的活动并打开 Facebook 对话框。但为什么?