Get friend list facebook 3.0

前端 未结 7 866
感情败类
感情败类 2020-12-12 22:57

I\'m trying to obtain my friend list from facebook using new SDK(3.0). I\'m facing problems related to what kind of params I need to insert in a Bundle and how to use newMyF

相关标签:
7条回答
  • 2020-12-12 23:08

    In getFriends() method, change this line:

    params.putString("fields", "id,name,friends");
    

    by

    params.putString("fields", "id, name, picture");
    
    0 讨论(0)
  • 2020-12-12 23:09

    You can use my code, you need to use the facebook library in your project. All the classes used for facebook are there in that sdk.

    private void onSessionStateChange(Session session, SessionState state,
            Exception exception) {
        if (state.isOpened()) {
            Log.i(TAG, "Logged in...");
            Request.executeMyFriendsRequestAsync(session,
                    new GraphUserListCallback() {
    
                        @Override
                        public void onCompleted(List<GraphUser> users,
                                Response response) {
                            Log.i("Response JSON", response.toString());
                            names = new String[users.size()];
                            id = new String[users.size()];
                            for (int i=0; i<users.size();i++){
                                names[i] = users.get(i).getName();
                                id[i]= users.get(i).getId();                                
                            }                           
                        }
                    });
        } else if (state.isClosed()) {
            Log.i(TAG, "Logged out...");
        }
    }
    

    names and ids are two String arrays and now have all the names and ids of the friends. I hope it solves your problem.

    0 讨论(0)
  • 2020-12-12 23:10

    Using FQL Query

    String fqlQuery = "SELECT uid,name,pic_square FROM user WHERE uid IN " +
            "(SELECT uid2 FROM friend WHERE uid1 = me())";
    
    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); 
    

    Ref : Run FQL Queries

    0 讨论(0)
  • 2020-12-12 23:21

    This should work:

    // @Deprecated
    // Request.executeMyFriendsRequestAsync()
    
    // Use this instead:
    Request.newMyFriendsRequest(session, new GraphUserListCallback() {
    
        @Override
        public void onCompleted(List<GraphUser> users, Response response) 
        {
            if(response.getError() == null)
            {
                for (int i = 0; i < users.size(); i++) {
                    Log.e("users", "users " + users.get(i).getName());
                }
            }
            else
            {
                Toast.makeText(MainActivity.this, 
                               response.getError().getErrorMessage(), 
                               Toast.LENGTH_SHORT).show();
            }
        }
    });
    
    0 讨论(0)
  • 2020-12-12 23:22

    For the person ask how obtein the first name and the last name, you need put first_name and last_name instead of name.

    params.putString("fields", "id, first_name, last_name, picture");
    
    0 讨论(0)
  • 2020-12-12 23:27

    Unfortunately Facebook remove those permissions.

    /me/friends returns the user's friends who are also using your app.

    In v2.0, the friends API endpoint returns the list of a person's friends who are also using your app. In v1.0, the response included all of a person's friends.

    In v1.0, it was possible to ask for permissions that would allow an app to see a limited amount of friend data, such as a person's friend's likes, their birthdays, and so on.

    In v2.0, those permissions have all been removed. It's no longer possible for an app to see data from a person's friends unless those friends have also logged into the app and granted permission for the app to see it that data

    https://developers.facebook.com/docs/apps/upgrading#v2_0_friendlist_title

    0 讨论(0)
提交回复
热议问题