[英]Facebook Android SDK 3.0 callback not called on cancel
I'm trying to upgrade an existing app/framework with Facebook Android SDK v3.0 but am stuck on how to authenticate with extra permissions. 我正在尝试用Facebook Android SDK v3.0升级现有的应用程序/框架,但我仍然坚持如何使用额外的权限进行身份验证。
The problem is that the StatusCallback does not seem to fire if the user cancels. 问题是如果用户取消,StatusCallback似乎不会触发。 If I use the regular call to
Session.openActiveSession
the callback fires on cancel, but using a new Session.OpenRequest
on fresh Session
object does not. 如果我使用对
Session.openActiveSession
的常规调用, Session.openActiveSession
在取消时触发回调,但在新的Session
对象上使用新的Session.OpenRequest
则不会。
Here's my code: 这是我的代码:
Session.OpenRequest auth = new Session.OpenRequest(this);
String[] permissions = {"publish_stream", "user_status"};
auth.setPermissions(Arrays.asList(permissions));
auth.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
auth.setCallback(new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
switch(state) {
case OPENING:
System.out.println("OPENING");
break;
case OPENED: // <-- NOT CALLED
System.out.println("OPENED");
break;
case CREATED: // <-- NOT CALLED
System.out.println("CREATED");
break;
case CREATED_TOKEN_LOADED: // <-- NOT CALLED
System.out.println("CREATED_TOKEN_LOADED");
break;
case OPENED_TOKEN_UPDATED: // <-- NOT CALLED
System.out.println("OPENED_TOKEN_UPDATED");
break;
case CLOSED: // <-- NOT CALLED
System.out.println("CLOSED");
break;
case CLOSED_LOGIN_FAILED: // <-- NOT CALLED
System.out.println("CLOSED_LOGIN_FAILED");
break;
}
}
});
Session session = new Session.Builder(this).setApplicationId("<My APP ID>").build();
session.openForPublish(auth);
This produces a view on the device like this: 这会在设备上生成如下视图:
http://cl.ly/image/0E2C0t2m2b0g http://cl.ly/image/0E2C0t2m2b0g
(FB app is not installed). (未安装FB应用程序)。 If the user clicks the close button (top left) the callback is NOT triggered.
如果用户单击关闭按钮(左上角),则不会触发回调。
If I use the Session.openActiveSession
in the same scenario the callback IS triggered. 如果我在同一场景中使用
Session.openActiveSession
, Session.openActiveSession
触发回调。
Is this a bug, or am I doing something wrong? 这是一个错误,还是我做错了什么?
Thanks! 谢谢!
Found the problem. 发现了问题。 When creating a session manually, one must set this session as the "active session" on the static Session instance:
在手动创建会话时,必须将此会话设置为静态Session实例上的“活动会话”:
Session session = new Session.Builder(this).setApplicationId("<My APP ID>").build();
Session.setActiveSession(session); // <-- MUST DO THIS
session.openForPublish(auth);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.