-1

Is there a backendless implementation using Facebook SDK code example out there somewhere? I have done this and i can't see the user's data in my backend.

Here is my code.

 private FacebookCallback<LoginResult> mCallBack = new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {

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



                            Backendless.UserService.loginWithFacebookSdk(LoginActivity.this,
                                    callbackManager,
                                    new AsyncCallback<BackendlessUser>() {
                                        @Override
                                        public void handleResponse(BackendlessUser response) {
                                            user = new User();
                                            user.setFacebookID((String) response.getProperty("id"));
                                            user.setName((String) response.getProperty("name"));
                                            user.setEmail((String) response.getProperty("email"));
                                            user.setGender((String) response.getProperty("gender"));
                                            user.setLocale((String) response.getProperty("locale"));
                                        }

                                        @Override
                                        public void handleFault(BackendlessFault fault) {
                                            Toast.makeText(getApplicationContext(), fault.getMessage(), Toast.LENGTH_SHORT).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());
        }
    }

Mappings

Map<String, String> facebookFieldMappings = new HashMap<String, String>() {{
                    put("id", "fb_id");
                    put("first_name", "fb_first_name");
                    put("last_name", "fb_last_name");
                    put("email", "email");
                    put("gender", "fb_gender");
                }};
Jay Rathod
  • 11,131
  • 6
  • 34
  • 58
Geob
  • 586
  • 5
  • 15

2 Answers2

1

In addition to what @Scadge said, you can use code generation built into Backendless Console. To do this:

  1. Click the Code Generation icon in Backendless console
  2. Select your client type (iOS/Android/JS)
  3. Select the "Facebook Login" checkbox
  4. Click the "Download Code" button at the bottom of the screen.
Mark Piller
  • 1,046
  • 1
  • 7
  • 6
  • I've made some headway thanks, the user data is getting saved in backendless table. Does backendlessPref have any role in determining user login status i.e redirecting to LoginActivity if user is not logged in from luancher Activity? – Geob Apr 29 '16 at 12:48
0

It is described in the documentation with code snippets: https://backendless.com/documentation/users/android/users_facebook_login.htm

Also there is a complete sample using it: https://github.com/Backendless/Android-SDK/tree/master/samples/UserService/FacebookSDKSamples

Scadge
  • 9,380
  • 3
  • 30
  • 39
  • in my backend, do i then create a table with columns "fb_id", "fb_first_name" etc from the mappings added to code? – Geob Apr 26 '16 at 16:54