Facebook new sdk - not able to get friends list

前端 未结 3 1174
醉话见心
醉话见心 2021-01-01 08:20

I am using the new Facebook-sdk and using the hackbook example to get the list of friends using FriendsList.java file. The Friendlist Activit

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-01 08:27

    Following code work better for me. This code provide friend list.

    public JSONObject getFrienList(String token)
    {
        InputStream is = null;
        String result = "";
        JSONObject jArray = null;
        try
        {
            HttpClient httpclient = new DefaultHttpClient();
            HttpGet httppost = new HttpGet("https://graph.facebook.com/me/friends?      access_token=" + token);
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            is = entity.getContent();
        }
        catch(Exception e)
        {
            Log.e("ERROR", "Error in http connection "+e.toString());
        }
        //convert response to string
        try
        {
            BufferedReader reader = new BufferedReader(new InputStreamReader(is),8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) 
            {
                sb.append(line + "\n");
            }
            is.close();
            result=sb.toString();
            Log.i("RESULT",result);
        }
        catch(Exception e)
        {
                Log.e("ERROR", "Error converting result "+e.toString());
        }
    
        //try parse the string to a JSON object
        try
        {
            jArray = new JSONObject(result);
            Log.i("RESULT","JSON ARRAY"+jArray.toString());
        }
        catch(JSONException e)
        {
                Log.e("ERROR", "Error parsing data "+e.toString());
        }
    
        return jArray;  
    }
    

提交回复
热议问题