Backendless Facebook SDK实现

时间:2016-04-26 15:04:55

标签: android facebook backendless

在某处使用Facebook SDK代码示例是否有后端实现?我已经这样做了,我无法在后端看到用户的数据。

这是我的代码。

 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());
        }
    }

映射

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");
                }};

2 个答案:

答案 0 :(得分:1)

除了@Scadge所说的,您还可以使用Backendless Console内置的代码生成功能。要做到这一点:

  1. 单击Backendless控制台中的代码生成图标
  2. 选择您的客户端类型(iOS / Android / JS)
  3. 选择“Facebook登录”复选框
  4. 点击屏幕底部的“下载代码”按钮。

答案 1 :(得分:0)