简体   繁体   中英

Android get Facebook friends with app downloaded FQL Query

I am trying to get the user's friends who have the app downloaded, I am using the following code

         String query = "SELECT uid FROM user WHERE is_app_user=1 and uid IN  (SELECT uid2 FROM friend WHERE uid1 =" + fbId + ")";
         Bundle params = new Bundle();
         params.putString("method", "fql.query");
         params.putString("query", query);
         mAsyncFacebookRunner.request(null, params, new FQLListener());

The code above makes a successful call. I am having trouble with getting what the call returns, which looks like this (A JSONArray)

    [{"uid":555555555},{"uid":000000000},{"uid":111111111},{"uid":222222222},{"uid":333333333}]

How do I put this information into something like an ArrayList?

Here is the RequestListener I am using.

 private class FQLListener implements RequestListener
    {

        @Override
        public void onComplete(String response, Object state) 
        {
            //get info here
        }
             }

Look at http://developer.android.com/reference/org/json/JSONArray.html to read JSONArray. You can try something like this :

JSONArray json = new JSONArray(server_response);
ArrayList<String> list = new ArrayList<String>();

for(int i = 0; i < json.length(); ++i){
    try{
        String uid = json.getJSONObject(i).getString("uid");
        list.add(uid);
    }
    catch(JSONException e){}
}
ArrayList<String> uids = new ArrayList<String>();

try {
    JSONArray jsonArr = new JSONArray(response);

    for (int i = 0; i < jsonArr.length(); i++)
    {
        uids.add(jsonArr.getJSONObject(i).getString("uid"));
    }
} catch (JSONException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM