I implemented successfully the code to make a request to the Facebook GraphRequest by using the the following code:

GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {   ... } 

In some documentation I found the code below to retrieve values:

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

I want to use System.out.println() to print out name and email of the person who logged in successfully with Facebook to my Android app. How can I invoke request to print out those values? Thank you.

UPDATE 1:

I suspect I might be experiencing the same problem reported at Facebook Integration Android: onCompleted(GraphJSONObjectCallback) block not executing: onCompleted(GraphJSONObjectCallback) block not executing

See more context of my code:

private void handleFacebookAccessToken(LoginResult loginResult) {   GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {     @Override     public void onCompleted(@Nullable JSONObject jsonObject, @Nullable GraphResponse graphResponse) {       //Access the response here and retrieve the information you want and print it out       String rawResponse = graphResponse.getRawResponse();       System.out.println("rawResponse: "+rawResponse);     });     Bundle parameters = new Bundle();     parameters.putString("fields","name,email");     request.setParameters(parameters);     request.executeAsync(); } 

I was expecting the following line to print out the response to the request, but I do not see anything printed out:

System.out.println("rawResponse: "+rawResponse); 

Tag:android, facebook-graph-api, facebook-login

4 comments.

  1. tomerpacific

    The GraphRequest.GraphJSONObjectCallback has a method called onCompleted that has two arguments:

    A JSONObject A GraphResponse

    You can access this response from inside the callback and print the values you want from there.

    GraphRequest request = GraphRequest.newMeRequest( accessToken, new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted(JSONObject object, GraphResponse response) { //Access the response here and retrieve the information you want and print it out String rawResponse = response. getRawResponse(); } });

    Reference

    1. Jaime Montoya

      See my UPDATE 1 to the question. Notice how System.out.println("rawResponse: "+rawResponse); is not printing out anything for me, which is strange.

    2. Jaime Montoya

      It works. It just takes forever for me to see the results. More than 2 minutes for the results from System.out.println("rawResponse: "+rawResponse); to be printed out. But I guess that is a different issue.

    3. tomerpacific

      @JaimeMontoya - That could be due to internet connection issues. After all, there is a request being made and it may take time.

Add a new comment.