5

Is field expansion supported in Facebook's Android SDK? where can I find an example?

There is great documentation on field expansion for the Graph APi. However, I cannot find any documentation for the android-sdk-3. Is it supported?

The problem starts when you want to do the following:

/me?fields=name,birthday,photos.limit(10).fields(id, picture)

In Facebook android SDK it seems that adding the parameters as a string doesn't work

E.g.

request = Request.newGraphPathRequest(session, "me/friendlists", new Request.Callback() {
    public void onCompleted(Response response) ...
}
Bundle parameters = new Bundle();
parameters.putString("fields","members.fields(id)", "list_type");
request.setParameters(parameters);
GenuinePlaceholder
  • 685
  • 1
  • 10
  • 25

2 Answers2

7
Session session = Session.getActiveSession();
    Bundle parameters = new Bundle(); 
    parameters.putString("fields","picture,description,source"); 
    new Request(session, /me/videos/uploaded, parameters, HttpMethod.GET,
            new Request.Callback() {
                public void onCompleted(Response response) {
                    GraphObject responseGraphObject = response
                            .getGraphObject();
                    JSONObject json = responseGraphObject
                            .getInnerJSONObject();
                    try {
                        JSONArray array = json.getJSONArray("data");
                        for (int i = 0; i < array.length(); i++) {
                            JSONObject main = array.getJSONObject(i);
                            String surce = main.optString("source");

                            String picture = main.optString("picture");

                            String videoname = main
                                    .optString("description");
                            System.out.println(surce);

                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }).executeAsync();

*get video data from faecbook by graph api and also put string in bundle *

wadali
  • 2,221
  • 1
  • 20
  • 38
  • 1
    also requests like that works fine: params.putString("fields", "birthday,email,gender,first_name,last_name,albums.limit(4){id,name}"); – Alexey Jan 04 '15 at 06:48
1

The Android SDK is used to make Graph API queries

You make the API calls with the same parameters and same return values as when making raw HTTP calls to graph.facebook.com or using the Graph API Explorer tool -

Just change your existing calls to the API to include the additional fields you want, following the syntax in the Field Expansion documentation, e.g. if you're currently calling /me/friends you can change it to /me/friends?fields=name,birthday

Igy
  • 43,710
  • 8
  • 89
  • 115
  • Indeed @Igy, you can add the parameters as you said. But the problem starts when you want to do the following:
    > /me?fields=name,birthday,photos.limit(10).fields(id, picture)
    In Facebook android SDK it seems that doesn't work adding the parameters as the example you mentioned because you have the field expansion within photos.
    – Raymundo Cornejo Jan 29 '13 at 21:08