脸书新SDK-无法获得好友列表[英] Facebook new sdk - not able to get friends list

本文是小编为大家收集整理的关于脸书新SDK-无法获得好友列表的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我正在使用新的Facebook-sdk并使用hackbook示例使用FriendsList.java文件获取朋友列表. Friendlist Activity每次都会被杀死,我在logcat中遇到此错误:

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

每次都可以再现.注意个人资料中的朋友数为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 !!!

请帮助!

推荐答案

我没有发布任何代码,因为我正在使用 facebook- hackbook for android. 最后,我找到了这个问题并解决了问题.

首先,问题不在Facebook SDK中,而是响应的大小.如果您在Facebook中有超过4K的朋友,并且使用 fql.query 或 Graph 方法查询朋友列表,则JSON响应大小超过500kb.现在,如果您尝试通过IPC(意图额外数据)将此500KB响应传递给另一个活动,则该过程因理性而失败!粘合剂交易失败! 有关失败粘合剂交易的更多信息,请访问失败的活页夹交易讨论

我如何解决这个问题: 我使用了与上面发布的链接中使用的相同过程. IE.编写对文件的响应并将文件链接发送到其他活动,而不是完整的500KB大小响应.

其他推荐答案

以下代码对我来说更好. 此代码提供朋友列表.

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;  
}

其他推荐答案

您现在在做什么,我不知道..因为您没有发布任何代码..但这是我获得朋友列表的方式.

加载朋友列表信息.

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();
        }

解析朋友的详细信息

 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;
      }

本文地址:https://www.itbaoku.cn/post/102663.html

问题描述

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!

推荐答案

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.

其他推荐答案

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;  
}

其他推荐答案

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;
      }