Reputation: 3
Trying to get Facebook Friends list to populate a Spinner object.Actually I can't seem to get the friends list at all and have been digging all over the place to get this to work. Using code found here early I have tried to get things to work with no luck.Any help would be GREATLY appreciated.Below are the pieces of code that pertain to this! At the moment I am not even trying to populate the spinner since I don't seem to be getting what I need. My List friends ends up having nothing in it with which to populate the spinner.
Bundle extras = getIntent().getExtras();
if (extras != null) {
Session s = (Session) extras.getSerializable("facebookSession");
if ((s!= null && s.isOpened()))
{
Log.d("FacebookSession", " is not null and is open");
}
else if ((s != null && !s.isOpened()))
{
Log.d("FacebookSession", " is not null and is not open");
}
else if (!(s != null))
{
Log.d("FacebookSession", " is null");
}
Session.setActiveSession((Session) extras.getSerializable("facebookSession"));
Session session = Session.getActiveSession();
SessionState state;
boolean i = session != null && session.isOpened();
String l;
if (i) { l = "true"; }
else { l = "false"; }
Log.d("Logged in", l);
if (i)
{
Log.d("tagging", "trying to get data");
getUserData(session, session.getState());
requestMyAppFacebookFriends(session);
}
}
Session is valid and ultimately works in my getUserData function call to populate user id and profile pic.
private Request createRequest(Session session) {
Request request = Request.newGraphPathRequest(session, "me/friends", null);
Set<String> fields = new HashSet<String>();
String[] requiredFields = new String[] { "id", "name", "picture"};
fields.addAll(Arrays.asList(requiredFields));
Bundle parameters = request.getParameters();
parameters.putString("fields", TextUtils.join(",", fields));
request.setParameters(parameters);
return request;
}
private void requestMyAppFacebookFriends(Session session) {
Request friendsRequest = createRequest(session);
friendsRequest.setCallback(new Request.Callback() {
@Override
public void onCompleted(Response response) {
List<GraphUser> friends = getResults(response);
// TODO: your code here
int x = friends.size();
Log.i("List of Friends size -> ", "" + x);
}
});
friendsRequest.executeAsync();
}
private List<GraphUser> getResults(Response response) {
GraphMultiResult multiResult = response
.getGraphObjectAs(GraphMultiResult.class);
GraphObjectList<GraphObject> data = multiResult.getData();
return data.castToListOf(GraphUser.class);
}
the Log.i("List of Friends size -> ", "" + x); outputs to log cat size zero
11-12 03:22:37.352 4300-4300/mobileapps.*************** I/List of Friends size ->﹕ 0
Please help
Upvotes: 0
Views: 110
Reputation: 758
As per new Facebook APIs one cannot get the friends list unless a friend authorizes your app. It is still possible to retrive friends list only if one uses older version of Facebook APIs/sdk..Hope this helps..I am able to successfully list my friends using older versions of facebook apis..
Upvotes: 1