Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static void refreshFriends(boolean firstStart) {
- GraphRequest request = GraphRequest.newMyFriendsRequest(accessToken, new GraphRequest.GraphJSONArrayCallback() {
- @Override
- public void onCompleted(JSONArray jsonArray, GraphResponse graphResponse) {
- // request successfully returned
- if (graphResponse.getError() == null) {
- Log.d("response length: ", Integer.toString(jsonArray.length()));
- Set<Friend> friends = new TreeSet<>(new Friend.NameComparator());
- for(int i = 0; i < jsonArray.length(); i++) {
- try {
- JSONObject user = jsonArray.getJSONObject(i);
- String name = user.getString("name");
- String id = user.getString("id");
- String imageUrl = user.getString("picture");
- Friend friend = new Friend(Long.parseLong(id), name, imageUrl);
- friends.add(friend);
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- if (firstStart) {
- friendListListener.onFirstAppStart(friends);
- } else {
- friendListListener.onAppStart(friends);
- }
- }
- }
- });
- Bundle parameters = new Bundle();
- parameters.putString("fields", "id,name,picture");
- request.setParameters(parameters);
- request.executeAsync();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement