5

当我使用 HTC Android 时,它做得很好。但是,当我使用 Facebook 的 API 使用三星 Android 4.2 登录时,我会显示一条 Toast 消息,例如“登录失败,请联系此应用的标记并要求他们向 facebook 发出 1732910”

请帮我修复它!

public class FacebookLogin {
/* variable Facebook */
private static final String FACEBOOK_APPID = "578073962236765";
private FacebookConnector facebookConnector;
private final Handler mFacebookHandler = new Handler();
ActivityBase activity;
Request.GraphUserCallback userCallback;
LoginService.OnSwimLogedInEvents swimLoginCallBack;
LoginService loginService;
Dialog changeDialog;
LoadingDialog loadingDialog;

public FacebookLogin(ActivityBase activity, Request.GraphUserCallback userCallback, LoginService.OnSwimLogedInEvents swimLoginCallBack) {
    this.activity = activity;
    this.loadingDialog = new LoadingDialog();
    this.userCallback = userCallback;
    this.swimLoginCallBack = swimLoginCallBack;
    this.loginService = new LoginService(activity);
    this.facebookConnector = new FacebookConnector(FACEBOOK_APPID,
            activity, activity, new String[]{
            "publish_stream", "email", "user_birthday", "read_stream", "offline_access"});
}

public void login() {
    Session.initializeStaticContext(activity);
    if (facebookConnector.getFacebook().isSessionValid()) {
        facebookConnector.getFacebook().getSession()
                .closeAndClearTokenInformation();
    }

    AuthListener listener = new AuthListener() {
        @Override
        public void onAuthSucceed() {
            doLogin();
        }

        @Override
        public void onAuthFail(String error) {
            //(new MessageAlert()).showDialog("Facebook authetication fail\r\nError:" + error, activity);
        }
    };
    SessionEvents.addAuthListener(listener);

    facebookConnector.login();
}

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    facebookConnector.getFacebook().authorizeCallback(requestCode, resultCode, data);
}

private void doLogin() {
    AsyncTaskBase<Void, Void, Void> t = new AsyncTaskBase<Void, Void, Void>(
            activity) {
        @Override
        protected Void doInBackground(Void... params) {
            mFacebookHandler.post(facebookUserInfoRunner);
            return super.doInBackground(params);
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            super.onPostExecute(aVoid);
        }
    };
    t.execute();
}

final Runnable facebookUserInfoRunner = new Runnable() {
    @Override
    public void run() {
       loadingDialog.showDialogLoading(activity);
        Request.executeMeRequestAsync(facebookConnector.getFacebook()
                .getSession(), new Request.GraphUserCallback() {

            @Override
            public void onCompleted(GraphUser user, Response response) {
                SwimAccount currentAccount = ((SwimApp) activity.getApplication()).getCurrentAccount();
                currentAccount.setAvatarUrl("https://graph.facebook.com/" + user.getId() + "/picture");
                currentAccount.setIsLogin(true);
                currentAccount.setFirstName(user.getFirstName());
                currentAccount.setLastName(user.getLastName());
                currentAccount.setStringId(user.getId());
                currentAccount.setAccountType("facebook");
                currentAccount.setEmail((String) response.getGraphObject().getProperty("email"));
                currentAccount.setBirthdate(user.getBirthday());
                currentAccount.setGender((String) response.getGraphObject().getProperty("gender"));
                if (userCallback != null) {
                    userCallback.onCompleted(user, response);
                }

                loginService.login(currentAccount.getEmail(), "", currentAccount.getAccountType(), currentAccount.getStringId(), swimLoginCallBack);
                //changeDialog.dismiss();
            }
        });
    }
};

}

4

2 回答 2

2

找到了解决我的问题的方法。尝试android:noHistory="true"从清单中的 Facebook 登录活动中删除 。这与 Session 的身份验证流程相混淆。

于 2013-08-27T10:10:45.813 回答
1

看起来 XDA 上的人也有同样的问题。

他们声称您可以尝试以下任何一种:

(1) 设置 > 开发者选项中的“不保留活动”选项。如果它处于打开状态,那么当应用程序调用某个弹出窗口时,系统会关闭应用程序,然后系统重新启动它......并且有你的循环。

(2) 如果您卸载了 Facebook App,您可以通过您的 App 登录,然后重新安装 Facebook App。

不确定这些答案有多“官方”,但认为这对你来说可能值得一试。

资料来源: http: //forum.xda-developers.com/showthread.php? p=43200939和http://forum.xda-developers.com/showthread.php?t=2186035

于 2013-08-28T14:48:20.113 回答