//----------------------------------------------------------------------- // // Copyright (c) Outercurve Foundation. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.ApplicationBlock { using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Runtime.Serialization; using System.Runtime.Serialization.Json; using System.Text; //// Documentation: https://developers.facebook.com/docs/reference/api/user/ [DataContract] public class FacebookGraph : IOAuth2Graph { private static DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(FacebookGraph)); /// /// Gets or sets the user's Facebook ID /// [DataMember(Name = "id")] public string Id { get; set; } /// /// Gets or sets the user's full name /// [DataMember(Name = "name")] public string Name { get; set; } /// /// Gets or sets the user's first name /// [DataMember(Name = "first_name")] public string FirstName { get; set; } /// /// Gets or sets the user's middle name /// [DataMember(Name = "middle_name")] public string MiddleName { get; set; } /// /// Gets or sets the user's last name /// [DataMember(Name = "last_name")] public string LastName { get; set; } /// /// Gets or sets the user's gender: female or male /// [DataMember(Name = "gender")] public string Gender { get; set; } /// /// Gets or sets the user's locale /// [DataMember(Name = "locale")] public string Locale { get; set; } /// /// Gets or sets the user's languages /// [DataMember(Name = "languages")] public FacebookIdName[] Languages { get; set; } /// /// Gets or sets the URL of the profile for the user on Facebook /// [DataMember(Name = "link")] public Uri Link { get; set; } /// /// Gets or sets the user's Facebook username /// [DataMember(Name = "username")] public string Username { get; set; } // age_range // third_party_id // installed /// /// Gets or sets the user's timezone offset from UTC /// [DataMember(Name = "timezone")] public int? Timezone { get; set; } /// /// Gets or sets the last time the user's profile was updated; changes to the languages, link, timezone, verified, interested_in, favorite_athletes, favorite_teams, and video_upload_limits are not not reflected in this value /// string containing an ISO-8601 datetime /// [DataMember(Name = "updated_time")] public string UpdatedTime { get; set; } // verified // bio /// /// Gets or sets the user's birthday /// Date string in MM/DD/YYYY format /// [DataMember(Name = "birthday")] public string Birthday { get; set; } [Obsolete] [DataMember(Name = "birthday_date")] public string BirthdayDate { get; set; } // cover // currency // devices // education /// /// Gets or sets the proxied or contact email address granted by the user /// [DataMember(Name = "email")] public string Email { get; set; } /// /// Gets or sets the user's hometown /// [DataMember(Name = "hometown")] public FacebookIdName Hometown { get; set; } /// /// Gets or sets the genders the user is interested in /// [DataMember(Name = "interested_in")] public string[] InterestedIn { get; set; } /// /// Gets or sets the user's current city /// [DataMember(Name = "location")] public FacebookIdName Location { get; set; } /// /// Gets or sets the user's political view /// [DataMember(Name = "political")] public string Political { get; set; } // payment_pricepoints /// /// Gets or sets the user's favorite athletes; this field is deprecated and will be removed in the near future /// [Obsolete] [DataMember(Name = "favorite_athletes")] public FacebookIdName[] FavoriteAthletes { get; set; } /// /// Gets or sets the user's favorite teams; this field is deprecated and will be removed in the near future /// [Obsolete] [DataMember(Name = "favorite_teams")] public FacebookIdName[] FavoriteTeams { get; set; } /// /// Gets or sets the URL of the user's profile pic (only returned if you explicitly specify a 'fields=picture' param) /// If the "October 2012 Breaking Changes" migration setting is enabled for your app, this field will be an object with the url and is_silhouette fields; is_silhouette is true if the user has not uploaded a profile picture /// [DataMember(Name = "picture")] public FacebookPicture Picture { get; set; } /// /// Gets or sets the user's favorite quotes /// [DataMember(Name = "quotes")] public Uri Quotes { get; set; } /// /// Gets or sets the user's relationship status: Single, In a relationship, Engaged, Married, It's complicated, In an open relationship, Widowed, Separated, Divorced, In a civil union, In a domestic partnership /// [DataMember(Name = "relationship_status")] public string RelationshipStatus { get; set; } /// /// Gets or sets the user's religion /// [DataMember(Name = "religion")] public string Religion { get; set; } // security_settings /// /// Gets or sets the user's significant other /// [DataMember(Name = "significant_other")] public FacebookIdName SignificantOther { get; set; } // video_upload_limits /// /// Gets or sets the URL of the user's personal website /// [DataMember(Name = "website")] public Uri Website { get; set; } public DateTime? BirthdayDT { get { if (!string.IsNullOrEmpty(this.Birthday) && (this.Locale != null)) { CultureInfo ci = new CultureInfo(this.Locale.Replace('_', '-')); return DateTime.Parse(this.Birthday, ci); } return null; } } public Uri AvatarUrl { get { if ((this.Picture != null) && (this.Picture.Data != null) && (this.Picture.Data.Url != null)) { return this.Picture.Data.Url; } return null; } } public HumanGender GenderEnum { get { if (this.Gender == "male") { return HumanGender.Male; } else if (this.Gender == "female") { return HumanGender.Female; } return HumanGender.Unknown; } } public static FacebookGraph Deserialize(string json) { if (string.IsNullOrEmpty(json)) { throw new ArgumentNullException("json"); } return Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(json))); } public static FacebookGraph Deserialize(Stream jsonStream) { if (jsonStream == null) { throw new ArgumentNullException("jsonStream"); } return (FacebookGraph)jsonSerializer.ReadObject(jsonStream); } public static class Fields { public const string Defaults = "id,name,first_name,middle_name,last_name,gender,locale,link,username"; public const string Birthday = "locale,birthday"; public const string Email = "email"; public const string Picture = "picture"; } /// /// Obsolete: used only before October 2012 /// [Obsolete] [DataContract] public class FacebookPicture { [DataMember(Name = "data")] public FacebookPictureData Data { get; set; } } /// /// Obsolete: used only before October 2012 /// [Obsolete] [DataContract] public class FacebookPictureData { [DataMember(Name = "url")] public Uri Url { get; set; } [DataMember(Name = "is_silhouette")] public bool IsSilhouette { get; set; } } [DataContract] public class FacebookIdName { [DataMember(Name = "id")] public string Id { get; set; } [DataMember(Name = "name")] public string Name { get; set; } } } }