我已将旧版本的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);
}
};