使用ParseFacebookUtil.login()登录facebook会返回null user和exception invalid date

时间:2015-04-02 15:30:47

标签: android facebook parse-platform facebook-login

我按照指示使用正确的app_id,parse_app_id,parse_client_id设置我的android项目。甚至使用ParseUI for Android注册一个新帐户&登录。但Facebook登录只是不起作用!

这是我的设置(更新到Parse-1.9.1& Facebook v4.0.1):

在我的应用中build.gradle:

compile project(':ParseLoginUI')
compile 'com.facebook.android:facebook-android-sdk:4.0.1'

在ParseLoginUI项目中,它的build.gradle(不是仅仅从repo复制的更改):

    dependencies {
        compile 'com.parse.bolts:bolts-android:1.2.0'
        compile 'com.android.support:support-v4:22.0.0'

        provided 'com.facebook.android:facebook-android-sdk:4.0.1'
        // This assumes that your app's project has a compile dependency on the Parse SDK JAR files.
        // Your project's build.gradle should say:
        //
        //     compile files('YOUR_PROJECT_LIBS_PATH/Parse-1.9.1.jar')
        //     compile files('YOUR_PROJECT_LIBS_PATH/ParseFacebookUtilsV4-1.9.1.jar')
        //
        // Since the dependency below is "provided" instead of "compile", your project's build.gradle
        // does not have to refer to the same Parse SDK instance that's in the ParseLoginUI/libs folder.
        provided files("$rootProject.projectDir/ParseLoginUI/libs/Parse-1.9.1.jar")
        provided files("$rootProject.projectDir/ParseLoginUI/libs/ParseFacebookUtilsV4-1.9.1.jar")
    }

点击登录按钮将运行:

facebookLoginButton = (Button) view.findViewById(R.id.fb_auth_button);
facebookLoginButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {

        onLoadingListener.onLoadingStart(false); // Facebook login pop-up already has a spinner

        if (config.isFacebookLoginNeedPublishPermissions()) {
            ParseFacebookUtils.logInWithPublishPermissionsInBackground(getActivity(),
                    config.getFacebookLoginPermissions(), facebookLoginCallbackV4);
        } else {
            ParseFacebookUtils.logInWithReadPermissionsInBackground(getActivity(),
                    config.getFacebookLoginPermissions(), facebookLoginCallbackV4);
        }
    }
});

private LogInCallback facebookLoginCallbackV4 = new LogInCallback() {
    @Override
    public void done(ParseUser user, ParseException e) {
        if (isActivityDestroyed()) {
            return;
        }

        if (user == null) {
            //loadingFinish();
            if (e != null) {
                Logger.d(getString(com.parse.ui.R.string.com_parse_ui_login_warning_facebook_login_failed) +
                        e.toString());
            }
            UIUtils.getSoldaToast(
                    getActivity(),
                    getString(com.parse.ui.R.string.com_parse_ui_facebook_login_failed_toast),
                    Gravity.CENTER).show();
        } else if (user.isNew()) {
            GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(),
                    new GraphRequest.GraphJSONObjectCallback() {
                        @Override
                        public void onCompleted(JSONObject fbUser,
                                                GraphResponse response) {
              /*
                If we were able to successfully retrieve the Facebook
                user's name, let's set it on the fullName field.
              */
                            ParseUser parseUser = ParseUser.getCurrentUser();
                            if (fbUser != null && parseUser != null
                                    && fbUser.optString("name").length() > 0) {
                                parseUser.put(USER_OBJECT_NAME_FIELD, fbUser.optString("name"));
                                parseUser.saveInBackground(new SaveCallback() {
                                    @Override
                                    public void done(ParseException e) {
                                        if (e != null) {
                                            Logger.d(getString(
                                                    com.parse.ui.R.string.com_parse_ui_login_warning_facebook_login_user_update_failed) +
                                                    e.toString());
                                        }
                                        loginSuccess();
                                    }
                                });
                            }
                            loginSuccess();
                        }
                    }
            ).executeAsync();
        } else {
            loginSuccess();
        }
    }
};

它始终返回null user& ParseException表示无效日期:

error-code-107

结帐doc,但仍然不知道我做错了什么。

顺便说一句,我确定我要评论Parse.enableLocalDatastore(this);以使其不是因为this bug。我要求的唯一facebook权限是email,因此呼叫将是

ParseFacebookUtils.logInWithReadPermissionsInBackground(
        getActivity(),
        config.getFacebookLoginPermissions(), 
        facebookLoginCallbackV4
);

更新到最新版本的ParseUI-android后,问题仍然存在。

有人经历过这个吗?

1 个答案:

答案 0 :(得分:1)

最后我解决了这个问题!朋友建议我delete the app from my facebook account确保重新开始。然后卸载Android应用以重新安装。 BOOOM!有用!谢谢Faceboooook。

希望这有帮助!