0

I think I just got the Facebook GraphRequest working, but I don't understand how to "extract" the Data. I know that you can get the Users Data by using:

object.getString("name")
etc...

But how does it work with the Users friends? /{user-id}/friends

EDIT: I had to paste the results to an JSONArray not into a single JSONObject!

Skyrisu
  • 373
  • 1
  • 5
  • 14

1 Answers1

0

When you use the graph API it returns a JSON object with the information you requested in your permissions. You are able to get the name using object.getString("name"); because name is one of the attributes in the graph response JSON, like this:

{
  "id": "12345678", 
  "birthday": "1/1/1950", 
  "first_name": "Chris", 
  "gender": "male", 
  "last_name": "Colm", 
  "link": "http://www.facebook.com/12345678", 
  "location": {
    "id": "110843418940484", 
    "name": "Seattle, Washington"
  }, 
  "locale": "en_US", 
  "name": "Chris Colm", 
  "timezone": -8, 
  "updated_time": "2010-01-01T16:40:43+0000", 
  "verified": true
}

This example was taken from the here, where it goes over the graph response.

Basically, you're going to have to traverse the JSON to get the information you want. A lot of people recommend org.json to do this in java, although I think you can probably do it just with built in Android tools.

Community
  • 1
  • 1
JoeBruzek
  • 509
  • 4
  • 16
  • When I use `object.getString("name")` it returns my name, but i want to return the name of my friend. – Skyrisu May 21 '15 at 22:06
  • Looking [here](https://developers.facebook.com/docs/graph-api/reference/v2.3/user/friends) it says that requesting `/{user-id}/friends` will return an array of user objects. You can find the user you want and then [get the name from there.](https://developers.facebook.com/docs/graph-api/reference/user/) – JoeBruzek May 22 '15 at 13:47