So here's my issue, I'm getting friends using request() and sometimes it works and I get all my friends, but sometimes, I won't get any friends, or I'll get some friends and not others. What's the best way to query facebook for friends? Should I wait a bit after querying initially? It's very frustrating.
Asked
Active
Viewed 534 times
2 Answers
0
This is all the coding that you need:
private void getFriends(){
progressDialog.setMessage("Loading friends list");
progressDialog.show();
firendsDialog = new Dialog(this);
//getting all friends of your facebook account
try
{
Bundle params = new Bundle();
params.putString(Facebook.TOKEN, accessToken);
mAsyncRunner.request("me/friends" , params , "GET", new RequestListener()
{
@Override
public void onMalformedURLException(MalformedURLException e, Object state)
{
}
@Override
public void onIOException(IOException e, Object state)
{
}
@Override
public void onFileNotFoundException(FileNotFoundException e, Object state)
{
}
@Override
public void onFacebookError(FacebookError e, Object state)
{
}
@Override
public void onComplete(String response, Object state)
{
try
{
JSONObject responseJsonObject = new JSONObject(response);
Log.d("TAG", "FB Response =>"+ responseJsonObject);
final JSONArray jsonArray = responseJsonObject.getJSONArray("data");
for (int i = 0; i < jsonArray.length(); i++)
{
map = new HashMap<String, String>();
JSONObject e = jsonArray.getJSONObject(i);
map.put("id", e.getString("id"));
map.put("name", e.getString("name"));
mylist.add(map);
userIds = e.getString("id");
userName = e.getString("name");
Log.d("MainActivity:getAllEvents", "Friend ID, Name:" + userIds + "," + userName);
}
}
catch (Exception e)
{
Log.e("log_tag", "Error parsing data "+e.toString());
}
}
Use the onComplete() to do whatever you want after getting your friends. I have added all friends to a map data structure.

TharakaNirmana
- 10,237
- 8
- 50
- 69
0
Using the graph API: https://graph.facebook.com/me/friends?access_token=22274xyz...........
For more information: https://developers.facebook.com/docs/graph-api/reference/v2.1/user/friends

JohnD
- 3,884
- 1
- 28
- 40

jcomeau_ictx
- 37,688
- 6
- 92
- 107
-
I'm getting this as a callback: `{"error":{"message":"Bad signature","type":"OAuthException"}}` and I'm doing exactly what you're saying. I'm assuming the 22274xyz is just an example? – hashtag_philippe Sep 26 '11 at 20:35
-
yep, I didn't want to give the world my permanent token, you can get your own after creating an app and going through the oauth dance. you can just set your callback URL to a CGI script that cats stdin to the screen for you. – jcomeau_ictx Sep 27 '11 at 01:00