Android登录并验证Facebook用户进入后端mbaas应用程序

时间:2016-04-24 23:17:58

标签: android facebook backendless

我已经完成了以下代码,可以成功验证并登录Facebook用户。

我已在构建gradle中编译'com.backendless:backendless:3.0.15.1'

private FacebookCallback<LoginResult> mCallBack = new FacebookCallback<LoginResult>() {
    @Override
    public void onSuccess(LoginResult loginResult) {
//        mDialog.dismiss();

        GraphRequest request = GraphRequest.newMeRequest(
                loginResult.getAccessToken(),
                new GraphRequest.GraphJSONObjectCallback() {
                    @Override
                    public void onCompleted(JSONObject object, GraphResponse response) {
                        Log.e("response: ", response + "");

                        user = new User();
                        user.facebookID = object.optString("id");
                        user.name = object.optString("name");
                        user.email = object.optString("email");
                        user.gender = object.optString("gender");
                        user.locale = object.optString("locale");

                        Utils.setCurrentUser(user, LoginActivity.this);

                        startActivity(new Intent(LoginActivity.this, MainActivity.class));
                        finish();

                        Toast.makeText(LoginActivity.this, "Logged in as " + user.name, Toast.LENGTH_LONG).show();
                    }
                }
        );

        Bundle parameters = new Bundle();
        parameters.putString("fields", "id, name, email, gender, locale, birthday, picture.width(80).height(80)");
        request.setParameters(parameters);
        request.executeAsync();
    }

    @Override
    public void onCancel() {
        Log.i(TAG, "LoginButton FacebookCallback onCancel");
    }

    @Override
    public void onError(FacebookException error) {
        Log.i(TAG, "LoginButton FacebookCallback onError:: "+error.getMessage());
        Log.i(TAG, "Exception:: "+error.getStackTrace());
    }
};

0 个答案:

没有答案