Search code examples
facebookfacebook-graph-apirestfb

RestFB parsing many objects into one incorrectly


My restFB code results in writing on one App to my ArrayList. I need the arraylist to fill out properly with the number of appIds return in JSON. Any insights?

Here is my code:

public List<String> fetchAppIdsForUser() {
    Connection<FacebookApp> appList = getClient().fetchConnection("me/applications/developer", FacebookApp.class);

    List<String> appIds = new ArrayList<String> ();
    for (List<FacebookApp> appListTwo : appList) {
          for (FacebookApp app : appListTwo) {
            appIds.add(app.getAppId());
          }
    }

    return appIds;
}

And here is what is returned in JSON:

{
   "data": [
      {
         "name": "x",
         "namespace": "x",
         "id": "x"
      },
      {
         "name": "xx",
         "namespace": "xx",
         "id": "xx"
      },
      {
         "name": "xxx",
         "namespace": "xxxx",
         "id": "xxxxx"
      },
      {
         "name": "xxxx",
         "namespace": "xxxxx",
         "id": "xxxxx"
      }
   ],
   "paging": {
      "next": "https://graph.facebook.com/xxxxx/applications?type=developer&format=json&access_token=XXXXXXXX"
   }
}

Solution

  • I solved it using the following:

    public List<String> fetchAppIdsForUser() {
        Connection<FacebookApp> appList = getClient().fetchConnection("me/applications/developer", FacebookApp.class);
        List<FacebookApp> list = appList.getData();
        ArrayList<String> appNames = new ArrayList<String>();
        for (FacebookApp app: list) {
            appNames.add(app.getName());
        }       
        return appNames;
    }