0
votes

I am using this code to get facbook friends but it give me error {"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}}

Please let me know what is i am doing wrong

this is my code :

    parameters.putString("format", "json");

    parameters.putString("token", args[0]);

    String url = "https://graph.facebook.com/me/friends";

    String response = Util.openUrl(url, "GET", parameters);

    JSONObject obj = Util.parseJson(response);

    Log.i("json Response", obj.toString());

    JSONArray array = obj.optJSONArray("data");
    return null;
1

1 Answers

0
votes

I used this method in order to get facebook friends with the app installed on their device, but with fql you can write your own query to suite your needs.

Something like this should do it.

 Session session = Session.getActiveSession();
    session.getAccessToken();

    String fqlQuery = "SELECT uid, name, pic_big FROM user WHERE is_app_user  " +
            "AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me())";

    Bundle params = new Bundle();
    params.putString("q", fqlQuery);

    Request request = new Request(session,
            "/fql",
            params,
            HttpMethod.GET,
            new Request.Callback() {

                @Override
                public void onCompleted(Response response) {

                    GraphObject graphObject = response.getGraphObject();

                    if (graphObject != null) {

                        if (graphObject.getProperty("data") != null) {
                            try {

                                JSONArray jArray =
                                        new JSONArray(graphObject.getProperty("data").toString());

                                for (int i = 0; i < jArray.length(); i++) {

                                    JSONObject jObject = jArray.getJSONObject(i);
                                }

                            } catch (Exception e) {

                            }
                        }
                    }
                }
            }
    );
    request.executeAsync();