Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Graph API field expansion in Android app

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);
like image 250
Raymundo Cornejo Avatar asked Jan 29 '13 02:01

Raymundo Cornejo


2 Answers

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 *

like image 199
wadali Avatar answered Sep 20 '22 08:09

wadali


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

like image 35
Igy Avatar answered Sep 22 '22 08:09

Igy