Exemplo n.º 1
0
        /// <summary>
        /// Retrieves a list of your Facebook friends using this application
        /// </summary>
        /// <param name="fbApplicationId"></param>
        /// <returns></returns>
        ///
        public List <FacebookFriend> GetApplicationFriends(String fbApplicationId)
        {
            if (String.IsNullOrEmpty(access_token))
            {
                throw new InvalidOperationException("Graph API access token not set");
            }

            List <FacebookFriend> friendsList = new List <FacebookFriend>();

            String applicationUrl      = String.Format(QUERY_URL, "SELECT uid, name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND is_app_user = 1", access_token);
            String applicationResponse = GetHttpRequest(applicationUrl);

            if (!String.IsNullOrEmpty(applicationResponse))
            {
                List <JObject> appFriends = JsonConvert.DeserializeObject <List <JObject> >(applicationResponse);
                foreach (JObject friendId in appFriends)
                {
                    friendsList.Add(FacebookFriend.Create(friendId));
                }
            }

            return(friendsList);
        }
Exemplo n.º 2
0
        public static FacebookFriend Create(JObject node)
        {
            FacebookFriend friend = new FacebookFriend();

            if (node != null)
            {
                JToken value = null;
                if (node.TryGetValue("id", out value))
                {
                    friend.id = node.SelectToken("id").Value <String>();
                }
                else if (node.TryGetValue("uid", out value))
                {
                    friend.id = node.SelectToken("uid").Value <String>();
                }
                if (node.TryGetValue("name", out value))
                {
                    friend.name = node.SelectToken("name").Value <String>();
                }
            }
            friend.pictureUrl = String.Format(FacebookConnection.RELATION_URL_PUBLIC, friend.id, "picture") + "?type=square";

            return(friend);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create
        ///
        /// Parses the standard Facebook user JSON object for the properties.  Note that picture
        /// has been added manually to be included in the user object
        /// </summary>
        /// <param name="jsonUser"></param>
        /// <returns></returns>
        ///
        public static FacebookUser Create(System.Web.Security.FormsIdentity identity, JObject jsonUser)
        {
            FacebookUser user = new FacebookUser();

            user.identity = identity;

            if (jsonUser != null)
            {
                JToken value = null;
                if (jsonUser.TryGetValue("id", out value))
                {
                    user.id = jsonUser.SelectToken("id").Value <String>();
                }
                if (jsonUser.TryGetValue("name", out value))
                {
                    user.name = jsonUser.SelectToken("name").Value <String>();
                }
                if (jsonUser.TryGetValue("first_name", out value))
                {
                    user.first_name = jsonUser.SelectToken("first_name").Value <String>();
                }
                if (jsonUser.TryGetValue("last_name", out value))
                {
                    user.last_name = jsonUser.SelectToken("last_name").Value <String>();
                }
                if (jsonUser.TryGetValue("gender", out value))
                {
                    user.gender = jsonUser.SelectToken("gender").Value <String>();
                }
                if (jsonUser.TryGetValue("link", out value))
                {
                    user.link = jsonUser.SelectToken("link").Value <String>();
                }
                if (jsonUser.TryGetValue("about", out value))
                {
                    user.about = jsonUser.SelectToken("about").Value <String>();
                }
                if (jsonUser.TryGetValue("bio", out value))
                {
                    user.bio = jsonUser.SelectToken("bio").Value <String>();
                }
                if (jsonUser.TryGetValue("birthday", out value))
                {
                    user.birthday = jsonUser.SelectToken("birthday").Value <String>();
                }
                if (jsonUser.TryGetValue("email", out value))
                {
                    user.email = jsonUser.SelectToken("email").Value <String>();
                }
                if (jsonUser.TryGetValue("hometown", out value))
                {
                    user.hometown = jsonUser.SelectToken("hometown").Value <String>();
                }
                if (jsonUser.TryGetValue("location", out value))
                {
                    user.location = jsonUser.SelectToken("location").Value <String>();
                }
                if (jsonUser.TryGetValue("quotes", out value))
                {
                    user.quotes = jsonUser.SelectToken("quotes").Value <String>();
                }
                if (jsonUser.TryGetValue("picture", out value))
                {
                    user.picture = jsonUser.SelectToken("picture").Value <String>();
                }
                if (jsonUser.TryGetValue("significant_other", out value))
                {
                    user.significant_other = FacebookFriend.Create((JObject)jsonUser.SelectToken("significant_other"));
                }
            }

            return(user);
        }