Facebook new sdk - not able to get friends list

前端 未结 3 1175
醉话见心
醉话见心 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条回答
  •  猫巷女王i
    2021-01-01 08:33

    What are you doing right now I don't know..cause you didn't posted any code..but this is how I got friend-list.

    To load Friend List Info.

    HttpGet httpget = new HttpGet("https://graph.facebook.com/me/friends?access_token=" + mAccessToken); 
            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();
            }
    

    To Parse Details of Friend

     private void parseJSON(String data1)
            {
            try{
                    JSONObject jObj = new JSONObject(data1);if(jObj==null) Log.i("-----------","JOBJ IS NULL");
                    JSONArray jObjArr= jObj.optJSONArray("data");if(jObjArr==null) Log.i("-----------","JOBJARR IS NULL");
                        int lon = jObjArr.length();
                        String  frnd_data[][] = new String[jObjArr.length()][2];
                        entity1 = new String[jObjArr.length()];
                        Log.i("Frineds >>", "" + lon);
                        for(int i = 0 ;i< lon; i++)
                            {
                              JSONObject tmp = jObjArr.optJSONObject(i);
                              frnd_data[i][0]=tmp.getString("name");
                              frnd_data[i][1]=tmp.getString("id");
                              Log.i("Name", frnd_data[i][0]);
                              Log.i("Name AND Id" , frnd_data[i][0] +"  "+ frnd_data[i][1]);
                              entity1[i] = getFriend("https://graph.facebook.com/"+frnd_data[i][1]+"?access_token="+mAccessToken);
                            }
                }
                catch (Exception e)
                {
                    Log.i("Exception1 >> ", e.toString());
                }
            }
          public String getFriend(String tmpurl) 
          {
              HttpClient httpclient = new DefaultHttpClient();
              String temp_result = null;
                HttpGet httpget = new HttpGet(tmpurl); 
                HttpResponse response;
                try
                {
                     response = httpclient.execute(httpget);
                        HttpEntity entity = response.getEntity();
                        if (entity != null)
                        {
                            temp_result = EntityUtils.toString(entity);
                            Log.i("Request String",temp_result);
                            return temp_result;
                        }
                }
               catch (Exception e) 
               {
                 e.printStackTrace();
               }
               return temp_result;
          }
    

提交回复
热议问题