Android facebook sdk 4.0 ProfileTracker onCurrentProfileChanged 永远不会被调用

标签 android facebook facebook-graph-api facebook-sdk-4.0

我正在尝试使用新的 Facebook SDK 4.5 版通过 ProfileTracker 类跟踪用户配置文件。当用户在我的应用程序中使用 Facebook 登录(并且设备中安装了 Facebook native 应用程序)时,它会在 native 应用程序中使用当前用户帐户成功登录。但是现在,如果用户从设备中的 native Facebook 应用程序注销并使用另一个用户帐户登录,而不是以前的帐户。我希望我的应用程序收到通知,告知用户现在已在 native 应用程序中更改了他的帐户/个人资料。为了实现我正在使用以下代码:

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");

}

我在 native Facebook 应用程序中使用帐户登录,然后在我的应用程序中使用 fb 成功登录。然后我从 native Facebook 应用程序注销并使用另一个帐户登录,但永远不会调用 onCurrentProfileChanged 来通知我配置文件已更改。我打印一个日志来检查它是否正在跟踪配置文件,它总是返回 true/yes。有帮助吗?

最佳答案

onCurrentProfileChanged()仅当您使用 LoginManager.getInstance().logOut() 显式注销用户然后尝试使用 LoginManager 对 Facebook 用户进行身份验证时才会被调用的 logIn 方法。

您的应用不会意识到用户已登录 Facebook 原生应用中的另一个帐户,ProfileTracker仅监视用于登录到您的应用的 Profile,而不监视它之外的内容。

关于Android facebook sdk 4.0 ProfileTracker onCurrentProfileChanged 永远不会被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32266082/

相关文章:

android - 为不同的 Activity 实现 admob

ios - 通过 iOS 登录 Facebook

python - Selenium -python 元素不可点击

android - 处理 Android Facebook API 的响应对象

python-2.7 - 如何通过http发送srt文件

android - 使用 FileProvider 在 Android N 上打开下载的文件

android - 如何在 MVVM 架构中使用来自 onActivityResult 的数据?

url - 从 URL 查找 Facebook ID

android - 菜单项选择不改变textview背景

android - 错误 Social Auth 4.4::无效范围:publish_stream。