public IFacebookApi Initialize(IFacebookSession session)
        {
            AuthToken = string.Empty;

            #if !SILVERLIGHT
            InstalledCulture = CultureInfo.InstalledUICulture;
            #else
            InstalledCulture = CultureInfo.CurrentUICulture;
            #endif

            Session = session;

            Auth = new Auth(Session);
            Video = new Video(Session);
            Marketplace = new Marketplace(Session);
            Admin = new Admin(Session);
            Photos = new Photos(Session);
            Users = new Users(Session);
            Friends = new Friends(Users, Session);
            Events = new Events(Session);
            Groups = new Groups(Session);
            Notifications = new Notifications(Session);
            Profile = new Profile(Session);
            Fbml = new Fbml(Session);
            Feed = new Feed(Session);
            Fql = new Fql(Session);
            LiveMessage = new LiveMessage(Session);
            Message = new Message(Session);
            Batch = new Batch(Session);
            Pages = new Pages(Session);
            Application = new Application(Session);
            Data = new Data(Session);
            Permissions = new Permissions(Session);
            Connect = new Connect(Session);
            Comments = new Comments(Session);
            Stream = new Stream(Session);
            Status = new Status(Session);
            Links = new Links(Session);
            Notes = new Notes(Session);
            Intl = new Intl(Session);

            Batch.Batch = Batch;
            Permissions.Permissions = Permissions;
            Batch.Permissions = Permissions;
            Permissions.Batch = Batch;

            foreach (IRestBase restBase in new IRestBase[] {Auth, Video, Marketplace, Admin, Photos, Users, Friends, Events,
                Groups, Notifications, Profile, Fbml, Feed, Fql, LiveMessage, Message, Pages, Application, Data, Connect, Comments,
                Stream, Status, Links, Notes})
            {
                restBase.Batch = Batch;
                restBase.Permissions = Permissions;
            }

            return this;
        }
 /// <summary>
 /// Logs in user
 /// </summary>
 public override void Login()
 {
     //check if session is valid
     Users users = new Users(this);
     users.GetLoggedInUserAsync(OnGetLoggedInUser, null);
 }
        private IList<user> GetUserObjects(long uid, long flid, bool isAsync, Users.GetInfoCallback callback, Object state)
        {
            if (Batch.IsActive)
            {
                throw new Exception("Extended API methods are not supported within a batch");
            }

            // TODO: change this method to use a FQL query instead

            var parameterList = new Dictionary<string, string> { { "method", "facebook.friends.get" } };
            Utilities.AddOptionalParameter(parameterList, "flid", flid);
            Utilities.AddOptionalParameter(parameterList, "uid", uid);

            if (isAsync)
            {
                SendRequestAsync<friends_get_response, IList<long>>(parameterList, (friends, state2, e) => OnGetFriendsCompleted(friends, callback, state2, e), state, "uid");
                return null;
            }

            var response = SendRequest<friends_get_response>(parameterList, !string.IsNullOrEmpty(Session.SessionKey)).uid;
            return _users.GetInfo(response);// StringHelper.ConvertToCommaSeparated(response));
        }
 private void OnGetFriendsCompleted(IList<long> friends, Users.GetInfoCallback callback, Object state, FacebookException e)
 {
     _users.GetInfoAsync(StringHelper.ConvertToCommaSeparated(friends), callback, state);
 }
        private IList<user> GetAppUsersObjects(bool isAsync, Users.GetInfoCallback callback, Object state)
        {
            if (Batch.IsActive)
            {
                throw new Exception("Extended API methods are not supported within a batch");
            }

            if (isAsync)
            {
                GetAppUsersAsync(new GetAppUsersCallback(OnGetAppUsersForObjectsCompleted), new object[] { callback, state });
                return null;
            }

            var users = GetAppUsers(false, null, null);
            return _users.GetInfo(new List<long>(users));// StringHelper.ConvertToCommaSeparated(users));
        }
 /// <summary>
 /// Returns the user objects for the specified user's Facebook friends.
 /// </summary>
 /// <example>
 /// <code>
 /// private static void RunDemoAsync()
 /// {
 ///     Api api = new Api(new DesktopSession(Constants.ApplicationKey, Constants.ApplicationSecret, Constants.SessionSecret, Constants.SessionKey));
 ///     api.Friends.GetUserObjectsAsync(Constants.UserId, Constants.FriendListId, AsyncDemoCompleted, null);
 /// }
 ///
 /// private static void AsyncDemoCompleted(IList&lt;user&gt; result, Object state, FacebookException e)
 /// {
 ///    var actual = result;
 /// }
 /// </code>
 /// </example>
 /// <param name="uid">The user ID for the user whose friends you want to return.</param>
 /// <param name="flid">Returns the friends in a friend list.</param>
 /// <param name="callback">The AsyncCallback delegate</param>
 /// <param name="state">An object containing state information for this asynchronous request</param>        
 /// <returns>This method returns the user objects for the specified user's friends.</returns>
 /// <remarks>The first array specifies one half of each pair, the second array the other half; therefore, they must be of equal size.</remarks>
 public void GetUserObjectsAsync(long uid, long flid, Users.GetInfoCallback callback, Object state)
 {
     GetUserObjects(uid, flid, true, callback, state);
 }
 /// <summary>
 /// Returns the user objects for the specified user's Facebook friends.
 /// </summary>
 /// <example>
 /// <code>
 /// private static void RunDemoAsync()
 /// {
 ///     Api api = new Api(new DesktopSession(Constants.ApplicationKey, Constants.ApplicationSecret, Constants.SessionSecret, Constants.SessionKey));
 ///     api.Friends.GetUserObjectsAsync(Constants.UserId, AsyncDemoCompleted, null);
 /// }
 ///
 /// private static void AsyncDemoCompleted(IList&lt;user&gt; result, Object state, FacebookException e)
 /// {
 ///    var actual = result;
 /// }
 /// </code>
 /// </example>
 /// <param name="uid">The user ID for the user whose friends you want to return.</param>
 /// <param name="callback">The AsyncCallback delegate</param>
 /// <param name="state">An object containing state information for this asynchronous request</param>        
 /// <returns>This method returns the user objects for the specified user's friends.</returns>
 /// <remarks>The first array specifies one half of each pair, the second array the other half; therefore, they must be of equal size.</remarks>
 public void GetUserObjectsAsync(long uid, Users.GetInfoCallback callback, Object state)
 {
     GetUserObjectsAsync(uid, -1, callback, state);
 }
 /// <summary>
 /// Returns the user objects for the current user's Facebook friends.
 /// </summary>
 /// <example>
 /// <code>
 /// private static void RunDemoAsync()
 /// {
 ///     Api api = new Api(new DesktopSession(Constants.ApplicationKey, Constants.ApplicationSecret, Constants.SessionSecret, Constants.SessionKey));
 ///     api.Friends.GetUserObjectsAsync(AsyncDemoCompleted, null);
 /// }
 ///
 /// private static void AsyncDemoCompleted(IList&lt;user&gt; result, Object state, FacebookException e)
 /// {
 ///    var actual = result;
 /// }
 /// </code>
 /// </example>
 /// <param name="callback">The AsyncCallback delegate</param>
 /// <param name="state">An object containing state information for this asynchronous request</param>        
 /// <returns>This method returns the user objects for the current user's friends.</returns>
 /// <remarks>The first array specifies one half of each pair, the second array the other half; therefore, they must be of equal size.</remarks>
 public void GetUserObjectsAsync(Users.GetInfoCallback callback, Object state)
 {
     GetUserObjectsAsync(-1, -1, callback, state);
 }
 /// <summary>
 /// Returns the user objects for the current user's Facebook friends who have authorized the specific calling application.
 /// </summary>
 /// <example>
 /// <code>
 /// private static void RunDemoAsync()
 /// {
 ///     Api api = new Api(new DesktopSession(Constants.ApplicationKey, Constants.ApplicationSecret, Constants.SessionSecret, Constants.SessionKey));
 ///     api.Friends.GetAppUsersObjectsAsync(AsyncDemoCompleted, null);
 /// }
 ///
 /// private static void AsyncDemoCompleted(IList&lt;user&gt; result, Object state, FacebookException e)
 /// {
 ///     var actual = result;
 /// }
 /// </code>
 /// </example>
 /// <param name="callback">The AsyncCallback delegate</param>
 /// <param name="state">An object containing state information for this asynchronous request</param>        
 /// <returns>The friend user objects returned are those friends who have authorized the calling application, which is a subset of the friends returned from the friends.get method.</returns>
 /// <remarks>The first array specifies one half of each pair, the second array the other half; therefore, they must be of equal size.</remarks>
 public void GetAppUsersObjectsAsync(Users.GetInfoCallback callback, Object state)
 {
     GetAppUsersObjects(true, callback, state);
 }