我正在使用最新的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 oficial“入门”文档做了一切
Android Facebook SDK3.0, session state OPENING
不起作用,因为Facebook身份验证对话框从不调用onActivityResult()
未安装Facebook应用程序。
更新
我检查了一下。session.openForPublish(openRequest);
关闭我的活动并打开Facebook Dialog。但为什么?
答案 0 :(得分:0)
使用UiLifeCycleHelper类更改会话状态。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
uiHelper = new UiLifecycleHelper(this, callback);
uiHelper.onCreate(savedInstanceState);
}