嘿,有人可以为我指出一个好的 Facebook 安卓教程的正确方向吗?他们的开发者网站的教程并不是那么好。
到目前为止,这是我想出的:
public static final int FBResultCode = 100;
private static Session.StatusCallback sharedFBStatusCallback = new Session.StatusCallback()
{
@Override
public void call(Session session, SessionState state, Exception exception)
{
if(exception != null)
Log.e("fb error", exception.toString());
switch(state)
{
case OPENED:
//login successful
break;
case CLOSED:
case CLOSED_LOGIN_FAILED:
closeFBSession();
break;
default:
break;
}
}
};
public static void openFBSessionWithLoginUI(boolean loginUI)
{
Session session = Session.getActiveSession();
if (session != null &&
!session.isOpened() &&
!session.isClosed())
{
ArrayList<String> perms = new ArrayList<String>();
perms.add("user_likes");
perms.add("user_birthday");
perms.add("read_friendlists");
Session.OpenRequest openRequest = new Session.OpenRequest(rootActivity)
.setCallback(sharedFBStatusCallback)
.setDefaultAudience(SessionDefaultAudience.FRIENDS)
.setLoginBehavior(loginUI? SessionLoginBehavior.SUPPRESS_SSO: SessionLoginBehavior.SSO_ONLY)
.setRequestCode(FBResultCode)
.setPermissions(perms);
session.openForRead(openRequest);
}
else
{
Session.openActiveSession(rootActivity, loginUI, sharedFBStatusCallback);
}
}
private static void closeFBSession()
{
Session currentSess = Session.getActiveSession();
if(currentSess != null)
{
currentSess.closeAndClearTokenInformation();
}
}
但是,这会返回一个错误:
E/fb 错误(3601):java.lang.UnsupportedOperationException:会话:试图打开一个有待处理请求的会话。
我究竟做错了什么?或者更好的是,处理 fb 登录的最佳方式是什么?