Android-Facebook SDK-如何判断用户是否更改了密码或从Facebook上的应用程序设置中删除了应用程序 [英] Android - Facebook SDK - how to tell if user changed password or removed app from app settings on Facebook

查看:101
本文介绍了Android-Facebook SDK-如何判断用户是否更改了密码或从Facebook上的应用程序设置中删除了应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当时正在使用Facebook开发人员网站上的测试用例来测试我们的应用程序.

I was testing our app using test cases from Facebook's developers site.

https://developers.facebook.com/docs/facebook-login/testing-your-login-flow

我们的应用未通过以下两个测试案例:

Our app failed two following test cases:

  1. 有人通过应用程序设置将您的应用程序从Facebook中删除,然后重新访问您的应用程序.您的应用应检测到此情况并提示对方 重新登录.

  1. Someone removes your app from Facebook via app settings and revisits your app. Your app should detect this and prompt the person to log back in.

  • 转到您的应用,然后点击使用Facebook登录"按钮.点击OK接受读取权限(再次点击OK接受写入权限) 权限(如果适用)

  • Go to your app and tap on the "Log in with Facebook" button Tap OK to accept the read permissions (and OK again to accept write permissions where applicable)

在Facebook上转到应用程序设置并删除您的应用程序

Go to app settings on Facebook and remove your app

重复步骤1-2,并验证Facebook登录是否有效

Repeat steps 1-2 and verify that Facebook Login works

有人用Facebook登录到您的应用程序后更改了Facebook密码.在这种情况下,您的令牌将无效,并且您 应通知用户其Facebook会话已过期并询问 他们再次登录.

Someone changes the Facebook password after logging in with Facebook to your app In this case, your token will be invalid and you should notify users that their Facebook session has expired and ask them to log in again.

  • 更改您的Facebook密码,然后选择从其他设备注销我"

  • Change your Facebook password and select "Log me out of other devices"

转到您的应用,然后点击使用Facebook登录"按钮

Go to your app and tap on the "Log in with Facebook" button

点击确定以接受读取权限(然后再次单击确定以接受写入权限)

Tap OK to accept the read permissions (and OK again to accept write permissions where applicable)

我一直在尝试在Facebook SDK上找到正确的方法,以了解如何进行检查.是否有这种方法可以告诉我用户需要再次登录(在更改密码或从Facebook网站上的应用程序设置中删除该应用程序的情况下)?

I have been trying to find the right method on the Facebook SDK for a way how to check this. Is there such method that would tell me that the user needs to log in again (in case of changing a password or removing the app from app settings on Facebook website)?

推荐答案

我最终进行了"me" API调用.如果在OAuthException上失败,则可以确定用户登录状态有问题.

I ended up making a "me" API call. If that fails on OAuthException I can be sure that something is wrong with the user login state.

    Action<JSONObject, GraphResponse> facebookMeCallbackAction =
        delegate (JSONObject jsonObject, GraphResponse graphResponse)
        {
            try
            {
                if (graphResponse.Error == null)
                {
                    // Do whatever we need to do in regards to Facebook
                }
                else
                {
                    if (graphResponse.Error.ErrorType.Equals(FacebookMeCallback.OAuthExceptionExceptionType, StringComparison.InvariantCultureIgnoreCase))
                    {
                        // Something wrong is with the login state, ask for reconnection to Facebook, etc.
                    }
                    else
                    {
                        // Something else went wrong
                    }
                }
            }
            catch (Exception ex)
            {
                Util.LogException(ex);
            }
        };

    using (var facebookCallback = new FacebookMeCallback(facebookMeCallbackAction))
    {
        var newMeRequest = GraphRequest.NewMeRequest(AccessToken.CurrentAccessToken, facebookCallback);
        GraphRequest.ExecuteAndWait(newMeRequest);
    }

这是FacebookMeCallback类:

Here is the FacebookMeCallback class:

public class FacebookMeCallback : Java.Lang.Object, GraphRequest.IGraphJSONObjectCallback
    {
        public const string OAuthExceptionExceptionType = "OAuthException";

        private readonly Action<JSONObject, GraphResponse> onCompletedFacebookCallbackAction;

        public FacebookMeCallback(Action<JSONObject, GraphResponse> onCompletedFacebookCallbackAction)
        {
            this.onCompletedFacebookCallbackAction = onCompletedFacebookCallbackAction;
        }

        public void OnCompleted(JSONObject jsonObject, GraphResponse graphResponse)
        {
            if (onCompletedFacebookCallbackAction != null)
                onCompletedFacebookCallbackAction(jsonObject, graphResponse);
        }
    }

这篇关于Android-Facebook SDK-如何判断用户是否更改了密码或从Facebook上的应用程序设置中删除了应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆