在获取电子邮件时从Facebook获取无效的json

时间:2015-07-07 11:09:35

标签: android facebook

使用graphrequest获取电子邮件时,我收到了无效的json。这是我的代码

    LoginManager.getInstance().registerCallback(callbackManager,
                new FacebookCallback<LoginResult>() {
                    @Override
                    public void onSuccess(LoginResult loginResult) {
                    GraphRequest request =GraphRequest.newMeRequest(loginResult.getAccessToken(),new GraphJSONObjectCallback() {

                        @Override
                        public void onCompleted(JSONObject object, GraphResponse response) {
                            // TODO Auto-generated method stub
                             Log.v("LoginActivity", response.toString());

                        }
                    });
                    Bundle parameters = new Bundle();
                    parameters.putString("fields","email");
                    request.setParameters(parameters);
                    request.executeAsync();
}

我从Facebook获得的Json回复如下:

{Response:  responseCode: 200, graphObject: {"id":"1592747474311684","email":"nanowebtech87@gmail.com"}, error: null}

如何解决这个问题。

1 个答案:

答案 0 :(得分:2)

请试试这个,

public void onCompleted(JSONObject object, GraphResponse response) {
                        // TODO Auto-generated method stub
                        try {
                            System.out.println("object :  " + object.toString());
                            String id=object.getString("id");
                            System.out.println("id"+ id);
                            String name=object.getString("name");
                            System.out.println("name"+ name);
                            String email=object.getString("email");
                            System.out.println("email"+ email);
                            String gender=object.getString("gender");
                            System.out.println("gender"+ gender);
                            String birthday=object.getString("birthday");
                            System.out.println("birthday"+ birthday);
                            //do something with the data here
                        } catch (JSONException e) {
                            e.printStackTrace(); //something's seriously wrong here
                        }





                    }