title: Facebook API how to wait til graphRequest executeAsync is done
body: <p>I am using facebook graph request to retrieve friends list. But, How can I get to create a function and return it after the call <code>graphRequest.executeAsync()</code> is done?.</p>
  
  <pre><code>private Map&lt;String, String&gt; getFacebookFriends(AccessToken accessToken, Profile profile) throws InterruptedException, ExecutionException {
      final Map&lt;String, String&gt; friendsMap = new HashMap&lt;&gt;();
      GraphRequest graphRequest = new GraphRequest(accessToken, "/me/friends", null, HttpMethod.GET,
              new GraphRequest.Callback() {
                  public void onCompleted(GraphResponse response) {
                      JSONObject jGraphObj = response.getJSONObject();
                      try {
                          JSONArray friendsData = jGraphObj.getJSONArray("data");
                          for (int i = 0; i &lt; friendsData.length(); i++) {
                              JSONObject friend = friendsData.getJSONObject(i);
                              String friendId = friend.getString("id");
                              String friendName = friend.getString("name");
                              friendsMap.put(friendId, friendName);
                          }
                      } catch (Exception e) {
                          e.printStackTrace();
                      }
                  }
              }
      );
      List&lt;GraphResponse&gt; gResponseList = graphRequest.executeAsync().get();
      return friendsMap;
  }
  </code></pre>
  
  <p>I am currently using the same technique like in <a href="https://stackoverflow.com/questions/14827532/waiting-till-the-async-task-finish-its-work">this post</a>. By calling it like <code>graphRequest.executeAsync().get();</code>. But it seems like it's not working.</p>
  
  <p>The function above will return the <code>friendsMap</code> before the <code>graphRequest</code> is done.</p>
  
  <p>Any suggestion is appreciated.</p>