Advertisement
Guest User

Untitled

a guest
Jun 13th, 2015
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None | 0 0
  1. private static void refreshFriends(boolean firstStart) {
  2.         GraphRequest request = GraphRequest.newMyFriendsRequest(accessToken, new GraphRequest.GraphJSONArrayCallback() {
  3.             @Override
  4.             public void onCompleted(JSONArray jsonArray, GraphResponse graphResponse) {
  5.                 // request successfully returned
  6.                 if (graphResponse.getError() == null) {
  7.                     Log.d("response length: ", Integer.toString(jsonArray.length()));
  8.                     Set<Friend> friends = new TreeSet<>(new Friend.NameComparator());
  9.                     for(int i = 0; i < jsonArray.length(); i++) {
  10.                         try {
  11.                             JSONObject user = jsonArray.getJSONObject(i);
  12.                             String name = user.getString("name");
  13.                             String id = user.getString("id");
  14.                             String imageUrl = user.getString("picture");
  15.                             Friend friend = new Friend(Long.parseLong(id), name, imageUrl);
  16.                             friends.add(friend);
  17.                         } catch (JSONException e) {
  18.                             e.printStackTrace();
  19.                         }
  20.                     }
  21.                     if (firstStart) {
  22.                         friendListListener.onFirstAppStart(friends);
  23.                     } else {
  24.                         friendListListener.onAppStart(friends);
  25.                     }
  26.                 }
  27.             }
  28.         });
  29.  
  30.         Bundle parameters = new Bundle();
  31.         parameters.putString("fields", "id,name,picture");
  32.         request.setParameters(parameters);
  33.         request.executeAsync();
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement