解析登录后如何才能收到facebook数据

时间:2015-12-15 09:54:55

标签: android facebook parse-platform

我在android中成功解析登录。但在这些之后我没有数据。我需要姓名,生日,邮件等......

我尝试了一些我在互联网上找到的方法,但是这些方法已被删除,在facebook sdk中找不到。

我的解析登录代码如下:

 Collection<String> permissions = new ArrayList<>();
    permissions.add("public_profile");
    permissions.add("email");
    permissions.add("user_birthday");
    // permissions.add("publish_actions");


    ParseFacebookUtils.logInWithReadPermissionsInBackground(activity, permissions, new LogInCallback() {
        @Override
        public void done(ParseUser parseUser, ParseException parseException) {

            if (parseException != null) {
                //succesfull login
            } else {
               //exceptions while logging
            }
        }
    });

在这些之后,我如何获得Facebook信息?

1 个答案:

答案 0 :(得分:0)

试试这个

getfbinfo.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

                    @Override
                    public void onSuccess(LoginResult result) {
                        Log.d("On result ", "On result");
                    //  finish();
                        AccessToken accessToken=result.getAccessToken();
                         GraphRequest request = GraphRequest.newMeRequest(
                                    accessToken,
                                    new GraphRequest.GraphJSONObjectCallback() {
                                        @Override
                                        public void onCompleted(
                                                JSONObject object,
                                                GraphResponse response) {
                                            Log.d("", "" + object+response);
                                            try {
                                                String userid = "";
                                                try {
                                                    userid = object.getString("id");
                                                } catch (Exception e1) {}
                                                String name = "";
                                                try {
                                                    name = object.getString("name");
                                                } catch (Exception e1) {}
                                                //final String email = object.getString("email");
                                                 String first_name = "";
                                                try {
                                                    first_name = object.getString("first_name");
                                                } catch (Exception e1) {}
                                                try {
                                                    String gender=object.getString("gender");
                                                } catch (Exception e1) {}
                                                String last_name;
                                                try {
                                                    last_name = object.getString("last_name");
                                                } catch (Exception e) {
                                                    last_name="";
                                                }
                                                try {
                                                    String link = object.getString("link");
                                                } catch (Exception e) {}
                                                //final String locale=object.getString("locale");
                                                //final String timezone=object.getString("timezone");
                                                //final String updated_time=object.getString("updated_time");
                                                //final String verified = object.getString("verified");



                                                        firstnameedittext.setText(first_name);
                                                        lastnameedittext.setText(last_name);



                                        }
                                    });
                            Bundle parameters = new Bundle();
                            parameters.putString("fields", "id,name,email,gender, birthday");
                           // parameters.putString("fields", "id,name,link,birthday,first_name,gender,location");
                            request.setParameters(parameters);
                            request.executeAsync();

                    }

                    @Override
                    public void onError(FacebookException error) {
                         Log.d("Error ", "Error");

                    }

                    @Override
                    public void onCancel() {
                        Log.d("cancle ", "cancle");

                    }
                });