/// <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); }
/// <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); }
/// <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) { try { 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["id"].ToString(); profile.FirstName = userProfile["first_name"].ToString(); profile.LastName = userProfile["last_name"].ToString(); profile.ProfilePicture = GetProfilePictureURL(userProfile["id"].ToString()); profile.UserName = userProfile["username"].ToString(); } } return profile; } catch (Exception ex) { throw ex; } }
/// <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; }