0

这是我获取朋友信息的方法:

private void getFriendsInfo() {
    if (currentSession != null && currentSession.isOpened()) {
        Log.d("fql started", "staarted");
        String fqlQuery = "select uid, name, hometown_location, pic_square from user where uid in (select uid2 from friend where uid1 = me() LIMIT 20)";
        Bundle params = new Bundle();
        params.putString("q", fqlQuery);
        Request request = new Request(currentSession, 
                "/fql", 
                params, 
                HttpMethod.GET, 
                new Request.Callback(){ 

            @Override
            public void onCompleted(Response response) {
                Log.i(TAG, "Got results: " + response.toString());
//here i want to assign String[] uid, name, location, image.
            }
        });
        Request.executeBatchAsync(request);
    } else {
        Log.d("getFriendsInfo", "else activated");
    }         
}

日志猫:

    Got results: {Response:  responseCode: 200, graphObject:GraphObject{graphObjectClass=GraphObject, 
    state={"data":[

    {"pic_square":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-ash2\/1115780_13962124_1029801849_q.jpg",
    "uid":13962124,
    "hometown_location":null,
    "name":"Jenny Rader"},

    {"pic_square":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-ash1\/276378_33807714_6690800_q.jpg",
    "uid":33807714,
    "hometown_location":null,
    "name":"John J. Rader"}

我已经搜索过了,但我只找到了如何从 Facebook 获取请求。

如何从 String[] uid, name, location, image 中的 fqlQuery 获取数据?

4

1 回答 1

2
Request request = new Request(session,"/fql",params,HttpMethod.GET,new Request.Callback(){         
                public void onCompleted(Response response) {

                            GraphObject graphObject = response.getGraphObject();


                            if (graphObject != null)
                            {
                                if (graphObject.getProperty("data") != null)
                                {
                                    try {
                                        String arry = graphObject.getProperty("data").toString();

                                        JSONArray jsonNArray = new JSONArray(arry);

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

                                            JSONObject jsonObject = jsonNArray.getJSONObject(i);

                                            String name = jsonObject.getString("name");
                                            String uid = jsonObject.getString("uid");

                                            String pic_square = jsonObject.getString("pic_square");
                                            String hoemtown = jsonObject.getString("hometown_location");

                                            Log.i("Entry", "uid: " + uid + ", name: " + name + ", pic_square: " + pic_square + ", hoemtown: " + hoemtown);
                                        }

                                    } catch (JSONException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                    }                                       
                                }
                            }

                    }                  
            }); 
            Request.executeBatchAsync(request);                 
        }
    });

将您的字段名称放入 jsonObject.getString("your field name")

于 2014-01-23T06:52:44.947 回答