Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The solution is to implement a RequestListener when making the request to the Facebook graph API. I have the new getFriends() method (see below) which uses the AsyncGacebookRunner to request the data.</p> <pre><code>public void getFriends(CharSequence[] charFriendsNames,String[] sFriendsID, ProgressBar progbar) { try{ //Pass arrays to store data friends = charFriendsNames; friendsID = sFriendsID; pb = progbar; Log.d(TAG, "Getting Friends!"); //Create Request with Friends Request Listener mAsyncRunner.request("me/friends", new FriendsRequestListener()); } catch (Exception e) { Log.d(TAG, "Exception: " + e.getMessage()); } } </code></pre> <p>The AsyncFacebookRunner makes the the request using the custom FriendsRequestListener (see below) which implements the RequestListener class;</p> <pre><code>private class FriendsRequestListener implements RequestListener { String friendData; //Method runs when request is complete public void onComplete(String response, Object state) { Log.d(TAG, "FriendListRequestONComplete"); //Create a copy of the response so i can be read in the run() method. friendData = response; //Create method to run on UI thread FBConnectActivity.this.runOnUiThread(new Runnable() { public void run() { try { //Parse JSON Data JSONObject json; json = Util.parseJson(friendData); //Get the JSONArry from our response JSONObject JSONArray friendArray = json.getJSONArray("data"); //Loop through our JSONArray int friendCount = 0; String fId, fNm; JSONObject friend; for (int i = 0;i&lt;friendArray.length();i++){ //Get a JSONObject from the JSONArray friend = friendArray.getJSONObject(i); //Extract the strings from the JSONObject fId = friend.getString("id"); fNm = friend.getString("name"); //Set the values to our arrays friendsID[friendCount] = fId; friends[friendCount] = fNm; friendCount ++; Log.d("TEST", "Friend Added: " + fNm); } //Remove Progress Bar pb.setVisibility(ProgressBar.GONE); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FacebookError e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } </code></pre> <p>Feel free to use any of this code in your own projects, or ask any questions about it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload