-1

是否有使用 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");
                }};
4

2 回答 2

1

除了@Scadge 所说的之外,您还可以使用 Backendless Console 中内置的代码生成。去做这个:

  1. 单击 Backendless 控制台中的代码生成图标
  2. 选择您的客户端类型(iOS/Android/JS)
  3. 选中“Facebook 登录”复选框
  4. 单击屏幕底部的“下载代码”按钮。
于 2016-04-27T16:01:34.293 回答
0

它在带有代码片段的文档中进行了描述:https ://backendless.com/documentation/users/android/users_facebook_login.htm

还有一个使用它的完整示例:https ://github.com/Backendless/Android-SDK/tree/master/samples/UserService/FacebookSDKSamples

于 2016-04-26T15:35:53.793 回答