当我使用 HTC Android 时,它做得很好。但是,当我使用 Facebook 的 API 使用三星 Android 4.2 登录时,我会显示一条 Toast 消息,例如“登录失败,请联系此应用的标记并要求他们向 facebook 发出 1732910”
请帮我修复它!
public class FacebookLogin {
/* variable Facebook */
private static final String FACEBOOK_APPID = "578073962236765";
private FacebookConnector facebookConnector;
private final Handler mFacebookHandler = new Handler();
ActivityBase activity;
Request.GraphUserCallback userCallback;
LoginService.OnSwimLogedInEvents swimLoginCallBack;
LoginService loginService;
Dialog changeDialog;
LoadingDialog loadingDialog;
public FacebookLogin(ActivityBase activity, Request.GraphUserCallback userCallback, LoginService.OnSwimLogedInEvents swimLoginCallBack) {
this.activity = activity;
this.loadingDialog = new LoadingDialog();
this.userCallback = userCallback;
this.swimLoginCallBack = swimLoginCallBack;
this.loginService = new LoginService(activity);
this.facebookConnector = new FacebookConnector(FACEBOOK_APPID,
activity, activity, new String[]{
"publish_stream", "email", "user_birthday", "read_stream", "offline_access"});
}
public void login() {
Session.initializeStaticContext(activity);
if (facebookConnector.getFacebook().isSessionValid()) {
facebookConnector.getFacebook().getSession()
.closeAndClearTokenInformation();
}
AuthListener listener = new AuthListener() {
@Override
public void onAuthSucceed() {
doLogin();
}
@Override
public void onAuthFail(String error) {
//(new MessageAlert()).showDialog("Facebook authetication fail\r\nError:" + error, activity);
}
};
SessionEvents.addAuthListener(listener);
facebookConnector.login();
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
facebookConnector.getFacebook().authorizeCallback(requestCode, resultCode, data);
}
private void doLogin() {
AsyncTaskBase<Void, Void, Void> t = new AsyncTaskBase<Void, Void, Void>(
activity) {
@Override
protected Void doInBackground(Void... params) {
mFacebookHandler.post(facebookUserInfoRunner);
return super.doInBackground(params);
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
}
};
t.execute();
}
final Runnable facebookUserInfoRunner = new Runnable() {
@Override
public void run() {
loadingDialog.showDialogLoading(activity);
Request.executeMeRequestAsync(facebookConnector.getFacebook()
.getSession(), new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
SwimAccount currentAccount = ((SwimApp) activity.getApplication()).getCurrentAccount();
currentAccount.setAvatarUrl("https://graph.facebook.com/" + user.getId() + "/picture");
currentAccount.setIsLogin(true);
currentAccount.setFirstName(user.getFirstName());
currentAccount.setLastName(user.getLastName());
currentAccount.setStringId(user.getId());
currentAccount.setAccountType("facebook");
currentAccount.setEmail((String) response.getGraphObject().getProperty("email"));
currentAccount.setBirthdate(user.getBirthday());
currentAccount.setGender((String) response.getGraphObject().getProperty("gender"));
if (userCallback != null) {
userCallback.onCompleted(user, response);
}
loginService.login(currentAccount.getEmail(), "", currentAccount.getAccountType(), currentAccount.getStringId(), swimLoginCallBack);
//changeDialog.dismiss();
}
});
}
};
}