I am working in one application in which I have to fetch all the friends list from Facebook.
I have implemented code like this :
Facebook mFacebook = new Facebook("141118172662401");
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(mFacebook);
Bundle params = new Bundle();
params.putString("fields", "name,id");
mAsyncRunner.request("me/friends", params, "GET", new FriendListRequestListener(), null);
}
});
}
public class FriendListRequestListener {
public void onComplete(final String response) {
_error = null;
try {
JSONObject json = Util.parseJson(response);
final JSONArray friends = json.getJSONArray("data");
FacebookFriendsActivity.this.runOnUiThread(new Runnable() {
JSONObject data;
public void run() {
try{
try {
data = Util.parseJson(response);
} catch (FacebookError e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JSONArray friendsData = data.getJSONArray("data");
// mDbAdapter.deleteAllFriends();
for (int i = 0; i < friendsData.length(); i++) {
JSONObject friend = friendsData.getJSONObject(i);
/* mDbAdapter.addFriend(friend.getString("name"),
friend.getString("id"));*/
}
}catch (Exception e) {
// TODO: handle exception
}
}
});
} catch (JSONException e) {
_error = "JSON Error in response";
} catch (FacebookError e) {
_error = "Facebook Error: " + e.getMessage();
}
if (_error != null)
{
FacebookFriendsActivity.this.runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(getApplicationContext(), "Error occurred: " +
_error, Toast.LENGTH_LONG).show();
}
});
}
}
}
Throws Error in this line :
mAsyncRunner.request(“me/friends”, params, “GET”, new FriendListRequestListener(), null);
What is wrong in this? also added Asyncronous class..
If there are any other methods or sources to find out Facebook friends then please let me know.
use this for getting
Friend List.
And for FriendsGetProfilePics