Example #1
0
        /// <summary>
        /// Gets all the Likes on a post
        /// </summary>
        /// <param name="postId">Facebook post ID</param>
        /// <returns>Returns list of likes for the post</returns>
        public IEnumerable <IFacebookProfile> GetAllLikesForPost(string postId)
        {
            #region Initialize URL and objects
            string Url  = string.Format("{0}/{2}/likes?access_token={1}", _baseUrl, AccessToken, postId);
            var    json = new JavaScriptSerializer();
            List <IFacebookProfile> profilesList = new List <IFacebookProfile>();
            #endregion

            using (var webClient = new WebClient())
            {
                string data = webClient.DownloadString(Url);

                #region Parse data
                var      likes      = (Dictionary <string, object>)json.DeserializeObject(data);
                object[] likesArray = (object[])likes.FirstOrDefault(p => p.Key == "data").Value;
                if (likesArray.Count() > 0)
                {
                    IFacebookProfile profile = null;
                    foreach (object like in likesArray)
                    {
                        Dictionary <string, object> like2 = (Dictionary <string, object>)like;
                        if (like2.Keys.Contains("name") && null != like2["name"])
                        {
                            profile = GetUserProfile(like2["id"].ToString());
                        }
                        profilesList.Add(profile);
                    }
                }
                #endregion
            }
            return(profilesList);
        }
Example #2
0
        /// <summary>
        /// Gets the Facebook User Profile
        /// </summary>
        /// <param name="profileId">Profile ID of the User</param>
        /// <returns>Returns the Facebook Profile for the User</returns>
        private IFacebookProfile GetUserProfile(string profileId)
        {
            string           Url     = string.Format("{0}/{2}?access_token={1}", _baseUrl, AccessToken, profileId);
            var              json    = new JavaScriptSerializer();
            IFacebookProfile profile = null;

            using (var webClient = new WebClient())
            {
                string data        = webClient.DownloadString(Url);
                var    userProfile = (Dictionary <string, object>)json.DeserializeObject(data);
                if (userProfile.Count() > 0)
                {
                    profile           = new FacebookProfile();
                    profile.Id        = (userProfile.ContainsKey("id"))?userProfile["id"].ToString():string.Empty;
                    profile.FirstName = (userProfile.ContainsKey("first_name"))?userProfile["first_name"].ToString():"- ";
                    profile.LastName  = (userProfile.ContainsKey("last_name"))?userProfile["last_name"].ToString() : "- ";
                    //profile.ProfilePicture = GetProfilePictureURL(userProfile["id"].ToString());
                    profile.UserName = (userProfile.ContainsKey("username"))?userProfile["username"].ToString():"- ";
                }
            }
            return(profile);
        }
Example #3
0
        /// <summary>
        /// Gets the Facebook Profile of a User by Email ID
        /// </summary>
        /// <param name="userEmail">Email ID of the User</param>
        /// <returns>Returns the User profile of the User</returns>
        private IFacebookProfile GetUserID(string userEmail)
        {
            string           Url     = string.Format("{0}/search?q={1}&type=user&access_token={2}", _baseUrl, userEmail, AccessToken);
            var              json    = new JavaScriptSerializer();
            IFacebookProfile profile = null;

            using (var webClient = new WebClient())
            {
                string data        = webClient.DownloadString(Url);
                var    userProfile = (Dictionary <string, object>)json.DeserializeObject(data);
                if (userProfile.Count() > 0)
                {
                    profile = new FacebookProfile();
                    object[] userProfileArray = (object[])userProfile.FirstOrDefault(p => p.Key == "data").Value;
                    foreach (object user in userProfileArray)
                    {
                        Dictionary <string, object> userProfileData = (Dictionary <string, object>)user;
                        profile = GetUserProfile(userProfileData["id"].ToString());
                    }
                }
            }
            return(profile);
        }