Android: get facebook friends list

前端 未结 8 1183
青春惊慌失措
青春惊慌失措 2020-11-29 06:53

I am using the Facebook SDK to post messages on walls.

Now I need to fetch the Facebook friends list. Can anybody help me with this?

-- Edit --



        
相关标签:
8条回答
  • 2020-11-29 07:43

    I faced the same problem yesterday. I wondering if you have overriden the onActivityResult() function?

    private Facebook mFacebook=null;
    
    ...
    ...
    ...
    
    @Override
    protected void onActivityResult(int requestCode, 
                                    int resultCode,
                                    Intent data) {
        mFacebook.authorizeCallback(requestCode, resultCode, data);
    }
    
    0 讨论(0)
  • 2020-11-29 07:44

    Using FQL Query

    String fqlQuery = "SELECT uid, name, pic_square FROM user WHERE uid IN " +
            "(SELECT uid2 FROM friend WHERE uid1 = me() LIMIT 25)";
    
    Bundle params = new Bundle();
    params.putString("q", fqlQuery);
    Session session = Session.getActiveSession();
    
    Request request = new Request(session,"/fql", params,HttpMethod.GET, new Request.Callback(){         
        public void onCompleted(Response response) {
            Log.i(TAG, "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); 
    
    0 讨论(0)
提交回复
热议问题