如何在facebook sdk获取facebook好友列表?

时间:2014-08-11 08:59:49

标签: android facebook facebook-graph-api facebook-fql

我正在尝试使用facebook sdk 3.0下面的代码获取facebook好友列表:

尝试1:

    String result;
    HttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet("https://graph.facebook.com/me/friends?access_token=" + token); 
    HttpResponse response;
    try
    {
         response = httpclient.execute(httpget);
            HttpEntity entity = response.getEntity();
            if (entity != null)
            {
                result = EntityUtils.toString(entity);
                Log.i("Request String",result);
                parseJSON(result);
            }
    }
    catch (Exception e) {
        e.printStackTrace();
    }

尝试2:

new Request(
                    session,
                    "/me/friends",
                    null,
                    HttpMethod.GET,
                    new Request.Callback() {
                        public void onCompleted(Response response) {
                           Log.e("Responseee",""+response);

                           if (response.getError() == null) {

                                Toast.makeText(getActivity().getApplicationContext(),
                                        "getting data successfully",
                                        Toast.LENGTH_SHORT).show();
                            } else {
                                Toast.makeText(
                                        getActivity().getApplicationContext(),
                                        response.getError()
                                                .getErrorMessage(),
                                        Toast.LENGTH_SHORT).show();

                            }

                        }
                    }
                ).executeAsync();

尝试3:

new Request(
            session,
            "/me/friendlists",
            null,
            HttpMethod.GET,
            new Request.Callback() {
                public void onCompleted(Response response) {
                   // handle the result 
                    Log.i("Result: ", "Result: " + response.toString());
                }
            }
        ).executeAsync();

尝试4:

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

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

            Request request = new Request(session,
                    "/fql",                         
                    params,                         
                    HttpMethod.GET,                 
                    new Request.Callback(){       
                public void onCompleted(Response response) {
                    Log.i("Result: ", "Result: " + response.toString());

                    try{
                        GraphObject graphObject = response.getGraphObject();
                        JSONObject jsonObject = graphObject.getInnerJSONObject();
                        Log.d("data", jsonObject.toString(0));

                        JSONArray array = jsonObject.getJSONArray("data");
                        for(int i=0;i<array.length();i++){

                            JSONObject friend = array.getJSONObject(i);

                            Log.d("uid",friend.getString("uid"));
                            Log.d("name", friend.getString("name"));
                            Log.d("pic_square",friend.getString("pic_square"));             
                        }
                    }catch(JSONException e){
                        e.printStackTrace();
                    }
                }                  
            }); 
            Request.executeBatchAsync(request); 

首先尝试低于响应。

结果:{Response:responseCode:200,graphObject:GraphObject {graphObjectClass = GraphObject,state = {&#34; data&#34;:[]}},error:null,isFromCache:false}

我知道facebook新SDK只允许那些安装了应用程序的朋友..如何获取生日,喜欢等朋友的详细信息,请告诉我新SDK的解决方案。

0 个答案:

没有答案