我在使用安装了 facebook 应用程序的 android 4.0.4 设备登录 facebook sdk 3.0.1 sdk 时遇到问题,代码在 Gingerbread 上运行良好
private Session openActiveSession(Activity activity, boolean allowLoginUI,
StatusCallback callback, List<String> permissions,
Bundle savedInstanceState) {
OpenRequest openRequest = new OpenRequest(activity)
.setPermissions(permissions)
.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK)
.setCallback(callback)
.setDefaultAudience(SessionDefaultAudience.FRIENDS);
Session session = Session.getActiveSession();
if (session == null) {
if (savedInstanceState != null) {
session = Session.restoreSession(this, null, fbStatusCallback,
savedInstanceState);
}
if (session == null) {
session = new Session(Login.this);
}
Session.setActiveSession(session);
if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)
|| allowLoginUI) {
session.openForRead(openRequest);
return session;
}
}
return null;
}
private Session.StatusCallback fbStatusCallback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state,
Exception exception) {
// callback for session state changes
if (state.isOpened()) {
Request.executeMeRequestAsync(session,
new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user,
Response response) {
if (user != null) {
if (response.getError() == null) {
JSONObject jsonObj = user
.getInnerJSONObject();
String dat = jsonObj.toString();
System.out
.println("The facebook response is >>>>"
+ dat);
WebServices wb = new WebServices();
sWrapper = wb.FacebookUserData(dat);
if (progress != null)
progress.dismiss();
SignupTaskForFaceBook st = new SignupTaskForFaceBook();
st.execute();
} else {
// Do something with the error
}
}
}
});
}
}
};
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode,
resultCode, data);
if(resultCode==RESULT_OK)
{
progress = ProgressDialog.show(Login.this, "",
"Fetching facebook user data");
}
}
没有收到异常或消息,它要求我获得许可,并且永远不会调用回调