Facebook new sdk - not able to get friends list

2019-02-11 12:32发布

I am using the new Facebook-sdk and using the hackbook example to get the list of friends using FriendsList.java file. The Friendlist Activity gets killed everytime and I am getting this error in the logcat:

11-18 16:20:51.141: ERROR/JavaBinder(7881): !!! FAILED BINDER TRANSACTION !!!.

The issue is reproducible everytime. Note number of friends in the profile are 4500.

11-18 16:19:27.932: DEBUG/Facebook-Util(7881): GET URL: https://api.facebook.com/restserver.php?access_token=**********&query=select+name%2C+current_location%2C+uid%2C+pic_square+from+user+where+uid+in+%28select+uid2+from+friend+where+uid1%3Dme%28%29%29+order+by+name&method=fql.query&format=json

11-18 16:20:50.982: WARN/InputManagerService(3426): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4665a200
11-18 16:20:51.141: ERROR/JavaBinder(7881): !!! FAILED BINDER TRANSACTION !!!

Please help!

3条回答
Anthone
2楼-- · 2019-02-11 13:20

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;
      }
查看更多
Animai°情兽
3楼-- · 2019-02-11 13:32

I didnt post any code because I was using the example code of Facebook sdk available at Facebook - Hackbook example for Android. Finally I found the issue and solved it.

First the issue is not in facebook sdk but with the size of the response. If you have more than 4k friends in facebook and you query for the friends list using fql.query or graph methods then the Json response size is more than 500kb. Now if you try to pass this 500kb response via IPC (Intent extra data) to another activity the process failed with reason !! Failed binder transaction !! More info on Failed binder transaction can be found at Failed binder transaction discussion

How I solved this issue: I used the same procedure as used in the link I have posted above. I.e. writing the response to a file and sending the file link to the other activity instead of the full 500kb size response.

查看更多
劫难
4楼-- · 2019-02-11 13:34

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;  
}
查看更多
登录 后发表回答