我已将旧版本的 Facebook sdk 更改为新版本 4.x 并通过登录管理器成功集成登录
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
// App code
Profile profile = Profile.getCurrentProfile();
fb_first_name = profile.getFirstName();
fb_last_name = profile.getLastName();
facebookId = profile.getId();
Log.print("System out", "fb_first_name-------------> "+fb_first_name+"\fb_last_name-------------> "+fb_last_name+"fbID-------------> "+facebookId);
}
@Override
public void onCancel() {
// App code
Toast.makeText(getApplicationContext(), "onCancel ", Toast.LENGTH_LONG).show();
}
@Override
public void onError(FacebookException exception) {
// App code
Toast.makeText(getApplicationContext(), "onError" +exception.toString() , Toast.LENGTH_LONG).show();
}
});
但是,当我logout
来自一个用户和login
另一个用户时,配置文件显示的是老用户。如何获取新用户的个人资料?我还尝试了下面的代码来获取更新的配置文件。
profileTracker = new ProfileTracker() {
@Override
protected void onCurrentProfileChanged(
Profile oldProfile,
Profile currentProfile) {
// App code
fb_first_name = currentProfile.getFirstName();
fb_last_name = currentProfile.getLastName();
facebookId = currentProfile.getId();
Log.print("System out", "fb_first_name-------------> "+fb_first_name+"\fb_last_name-------------> "+fb_last_name+"fbID-------------> "+facebookId);
Toast.makeText(getApplicationContext(), "onSuccess"+currentProfile.getName(), Toast.LENGTH_LONG).show();
handler.sendEmptyMessage(0);
}
};