Question

I'm trying to create a method for returning page name and page photo from a list of page id's, the requests seem to be returning null, a solution to the problem will be as much appreciated as a suggestion for a better method for what im trying to achieve.

public void getPages(){


    for(int f=0;f<Json.PI;f++){
         final int j = f;
    final Request photo = new Request(
            null,
            "/" + PhotoId,
            null,
            HttpMethod.GET,
            new Request.Callback() {
                public void onCompleted(Response response) {

                    GraphObject graphObject = response.getGraphObject();
                    JSONObject jsonObject = graphObject.getInnerJSONObject();

                    try {
                        PageInfo[j][1] = (String) jsonObject.get("picture");

                        Log.i("PICTURE", PageInfo[j][1]);
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }




                }
            }
        );

    final Request photos = new Request(
            MainFragment.activeSession,
            "/"+likes[f]+"/photos/uploaded",
            null,
            HttpMethod.GET,
            new Request.Callback() {
                public void onCompleted(Response response) {

                    GraphObject graphObject = response.getGraphObject();
                    JSONObject jsonObject = graphObject.getInnerJSONObject();
                    try {
                        JSONArray array = jsonObject.getJSONArray("data");
                        JSONObject object = (JSONObject) array.get(0);
                        Log.i("PHOTOID", (String) object.get("id"));
                        PhotoId = (String) object.get("id");

                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    Log.i("PNAME", String.valueOf(response));



                }
            }
        );

    Request PageID = new Request(MainFragment.activeSession, "/"+likes[f], null, HttpMethod.GET, new Request.Callback() {


                public void onCompleted(Response response) {

                    Log.i("RESP", String.valueOf(response));


                }

    }
        );



    Requests.add(PageID);
    Requests.add(photos);
    Log.i("TAG", "ADDED");
     }
    Requests.executeAsync();

the response from facebook is as follows

{Response:  responseCode: 400, graphObject: null, error: {HttpStatus: -1, errorCode: -1, errorType: null, errorMessage: Unexpected number of results}, isFromCache:false}

why is it returning null?

Was it helpful?

Solution

Why don't you use a FQL query:

select page_id, name, pic from page where page_id in ({your_comma_separated_list_of_page_ids})

This will then only need one request. Use the

GET /fql?q={your_urlencoded_query}&access_token={your_access_token}

endpoint.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top