Nou*_*tti 6 android facebook facebook-graph-api facebook-sdk-4.0
我正在尝试使用新的Facebook sdk 4.5版跟踪ProfileTracker类的用户配置文件.当用户在我的应用程序中使用Facebook登录(并且Facebook本机应用程序安装在设备中)时,它将使用本机应用程序中的当前用户帐户成功登录.但现在,如果用户从设备中的本机Facebook应用程序注销,并使用另一个用户帐户登录,而不是之前的用户帐户.我希望我的应用程序收到通知,现在用户已在原生应用中更改了他的帐户/个人资料.为了实现我正在使用以下代码:
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
setContentView(R.layout.activity_homescreen);
uIint();
LoginManager.getInstance().registerCallback(callbackManager, this);
profileTracker = new ProfileTracker() {
@Override
protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {
if (oldProfile != null) {
Log.i(getClass().getSimpleName(), "profile oldProfile: " + oldProfile.getFirstName());
}
if (currentProfile != null) {
Log.i(getClass().getSimpleName(), "profile currentProfile: " + currentProfile.getFirstName());
}
}
};
profileTracker.startTracking();
if(profileTracker.isTracking())
Log.i(getClass().getSimpleName(), "profile currentProfile Tracking: " + "yes");
else
Log.i(getClass().getSimpleName(), "profile currentProfile Tracking: " + "no");
}
@Override
public void onSuccess(LoginResult loginResult) {
//Utils.showToast_msg(context, "Login success");
getFbProfileInfo();
}
@Override
public void onCancel() {
Utils.showToast_msg(context, "Login onCancel");
}
@Override
public void onError(FacebookException e) {
Utils.showToast_msg(context, "Login onError");
}
Run Code Online (Sandbox Code Playgroud)
我使用原生Fb应用程序中的帐户登录,然后在我的应用程序中成功登录fb.然后我从本地Fb应用程序注销并使用另一个帐户登录但是onCurrentProfileChanged永远不会被调用以通知我该配置文件已被查询.我打印一个日志来检查它是否跟踪配置文件,它总是返回true/yes.有帮助吗?
onCurrentProfileChanged()仅当您明确使用注销用户LoginManager.getInstance().logOut(),然后尝试使用 FacebookLoginManager的logIn方法对用户进行身份验证时,才会被调用。
您的应用程序不会意识到用户已登录 Facebook 本机应用程序中的另一个帐户,ProfileTracker只会监视Profile用于登录您的应用程序的帐户,而不监视其外部的帐户。
| 归档时间: |
|
| 查看次数: |
1008 次 |
| 最近记录: |