Click here to Skip to main content
15,894,896 members
Articles / Desktop Programming / WPF

Getting Started with Facebook Desktop (Client) Applications, C#, WPF / XAML and JSON

Rate me:
Please Sign up or sign in to vote.
4.92/5 (28 votes)
21 Jan 2009CPOL15 min read 320.7K   11.7K   139  
A take on getting started with the Facebook API and WPF
using System;
using System.Runtime.Serialization;

// Namespace does not match code / folder hierarchy as I wanted it to reflect the facebook structure
namespace Facebook.users
{
    /// <summary>
    /// Type that can be serialised from JSON to a .net class
    /// http://wiki.developers.facebook.com/index.php/Users.getInfo
    /// </summary>
    [DataContract]
    public class getInfo
    {
        [DataMember]
        public string first_name { get; set; }

        [DataMember]
        public string last_name { get; set; }

        [IgnoreDataMember] // Marked as ignore as it is not to be populated from the facebook lookup(i.e. not a facebook field)
        public string full_name { get { return String.Format("{0} {1}", first_name, last_name); } } 

        [DataMember]
        public string pic_big { get; set; }

        [DataMember]
        public string pic_small { get; set; }

        [DataMember]
        public string profile_url { get; set; }

        [DataMember]
        public hs_info hs_info { get; set; }

        [DataMember]
        public hometown_location hometown_location { get; set; }

        [DataMember]
        public status status { get; set; }
    }

    /// <summary>
    /// High School Info
    /// </summary>
    [DataContract]
    public class hs_info
    {
        [DataMember]
        public string hs1_name { get; set; }

        [DataMember]
        public string hs2_name { get; set; }

        [DataMember]
        public string grad_year { get; set; }

        [DataMember]
        public string hs1_id { get; set; }

        [DataMember]
        public string hs2_id { get; set; }
    }

    /// <summary>
    /// "Hometown" profile fields. Contains three children: city, state, and country. 
    /// </summary>
    [DataContract]
    public class hometown_location
    {
        [DataMember]
        public string city { get; set; }

        [DataMember]
        public string state { get; set; }

        [DataMember]
        public string country { get; set; }
    }

    /// <summary>
    /// The user's facebook status 
    /// </summary>
    [DataContract]
    public class status
    {
        [DataMember]
        public string message { get; set; }

        [DataMember]
        public double time { get; set; }

        // Property to return the time in a .net friendly datetime instead of the unix EPOC time
        [IgnoreDataMember] // Marked as ignore as it is not to be populated from the facebook lookup(i.e. not a facebook field)
        public DateTime time_DateTime { get { return Facebook.Helpers.ConvertUnixTimestampToDotNet(time); } }

        [DataMember]
        public string status_id { get; set; }

        // Property to return a full string of all the status elements
        [IgnoreDataMember] // Marked as ignore as it is not to be populated from the facebook lookup(i.e. not a facebook field)
        public string status_line
        {
            get
            {
                if (time != 0) // only format and return a status if there is one, otherwise return "not set".
                    return (String.Format("{0} (Set on: {1} at {2})", message, time_DateTime.ToLongDateString(), time_DateTime.ToLongTimeString()));
                else
                    return "Not set";
            }
        }
    }
}
 

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
United Kingdom United Kingdom
You can read more about me here:

http://uk.linkedin.com/in/murrayfoxcroft

Comments and Discussions