Get user friends list

Sep 1, 2009 at 8:16 AM

Hi All,

I'm quite new here, and i tryed to find how can i get a user friends list

from call within the server side.

Appreciate  the help,

Oct 14, 2009 at 5:45 PM

I have an application that I host outside of facebook and this is what I use:

facebook.Components.FacebookService _fbService = new facebook.Components.FacebookService();

string KEY = ConfigurationManager.AppSettings["APIKey"].ToString();
string SECRET = ConfigurationManager.AppSettings["Secret"].ToString();
_fbService.ApplicationKey = KEY;
_fbService.Secret = SECRET;
_fbService.IsDesktopApplication = false;

string sessionKey = "";
string userId = "";

if (Session["facebook_session_key"] != null)
{
 sessionKey = Session["facebook_session_key"].ToString();
}

if (Session["facebook_userId"] != null)
{
 userId = Session["facebook_userId"].ToString();
}

// When the user uses the facebook login page,
// the redirect back here will will have the auth_token in the query params
string authToken = Request.QueryString["auth_token"];
if (!String.IsNullOrEmpty(sessionKey))
{
 _fbService.SessionKey = sessionKey;
 _fbService.uid = long.Parse(userId);
}
else if (!String.IsNullOrEmpty(authToken))
{
 _fbService.CreateSession(authToken);
 Session["facebook_session_key"] = _fbService.SessionKey;
 Session["facebook_userId"] = _fbService.uid.ToString();
 Session["facebook_session_expires"] = _fbService.SessionExpires;
}
else
{
 Response.Redirect(@"http://www.facebook.com/login.php?api_key=" +
   _fbService.ApplicationKey + @"&v=1.0");
}

if (!IsPostBack)
{
 var friends = _fbService.friends.getUserObjects();
 foreach (facebook.Schema.user friend in friends)
 {
  //do whatever you want here
 }
}

I'm sure you've visited the wiki as well but just in case you havn't check out http://wiki.developers.facebook.com/index.php/API