0

I am trying to extract information from a user that logs into my android application using Facebook. I am getting a cannot resolve method when getInnerJSONResponse().

@Override
                    public void onCompleted(JSONObject object, GraphResponse response) {
                        ParseUser user = new ParseUser();

                        JSONObject jsonResponseObject = user.getInnerJSONObject();
                        String email = jsonResponseObject.getProperty("email");
//                        String firstName = jsonResponseObject.getFirstName();
//                        String lastName = jsonResponseObject.getLastName();
                    }
                });
                Bundle param = new Bundle();
                param.putString("fields", "cover, birthday, email, first_name, last_name, ");
                request.setParameters(param);
                request.executeAsync();

2 Answers2

0

Try to use:

 String email = jsonResponseObject.getString("email");
 String firstName = jsonResponseObject.getString("first_name");
 String lastName = jsonResponseObject.getString("last_name");

etc.

See documentation

dieter_h
  • 2,707
  • 1
  • 13
  • 19
  • That solved the email error but I still need to fix getting the json response other's I will have no email to extract. – Tomasz Ksepka Sep 03 '15 at 18:25
  • I tried the method above but the app crashes because the JSONObject is null. – Tomasz Ksepka Sep 03 '15 at 18:44
  • Run in debug mode and see respone objects `JSONObject object` and `GraphResponse response` – dieter_h Sep 03 '15 at 18:46
  • The response returns a 400 response code so the object is in fact null. It also returns "An active access token must be used to query information...". Thank you for the help, I think I see the problem. It' not in the code above but I must be getting the access token wrong. – Tomasz Ksepka Sep 03 '15 at 19:03
  • First, you need to have access token. – dieter_h Sep 03 '15 at 19:06
  • Yes I know, I'm using getAccesToken() but it returns null so I'm trying to figure that out now. Thanks for the help. – Tomasz Ksepka Sep 03 '15 at 19:32
0

Use this code.Check this Answer.

loginButton = (LoginButton) findViewById(R.id.login_button);

List < String > permissionNeeds = Arrays.asList("user_photos", "email",
 "user_birthday", "public_profile", "AccessToken");
loginButton.registerCallback(callbackManager,
new FacebookCallback < LoginResult > () {@Override
 public void onSuccess(LoginResult loginResult) {

  System.out.println("onSuccess");

  String accessToken = loginResult.getAccessToken()
   .getToken();
  Log.i("accessToken", accessToken);

  GraphRequest request = GraphRequest.newMeRequest(
  loginResult.getAccessToken(),
  new GraphRequest.GraphJSONObjectCallback() {@Override
   public void onCompleted(JSONObject object,
   GraphResponse response) {
    Log.i("LoginActivity", response.toString());
    try {
     id = object.getString("id");
     try {
      URL profile_pic = new URL(
       "http://graph.facebook.com/" + id + "/picture?type=large");
      Log.i("profile_pic",
      profile_pic + "");

     } catch (MalformedURLException e) {
      e.printStackTrace();
     }
     name = object.getString("name");
     email = object.getString("email");
     gender = object.getString("gender");
     birthday = object.getString("birthday");
    } catch (JSONException e) {
     e.printStackTrace();
    }
   }
  });
  Bundle parameters = new Bundle();
  parameters.putString("fields",
   "id,name,email,gender, birthday");
  request.setParameters(parameters);
  request.executeAsync();
 }

 @Override
 public void onCancel() {
  System.out.println("onCancel");
 }

 @Override
 public void onError(FacebookException exception) {
  System.out.println("onError");
  Log.v("LoginActivity", exception.getCause().toString());
 }
});
Community
  • 1
  • 1
Harvi Sirja
  • 2,472
  • 2
  • 18
  • 19