Tag Archives: C#

Microsoft Visual C# is simple, modern, general-purpose, object-oriented programming language, included in the Microsoft Visual Studio. Visual C# is also mostly used in ASP.NET web sites and Windows applications

How to get count of Likes of the your facebook page in C#

get number of like of Facebook page
With the help of Facebook Graph API, we can get various information about any Facebook page. The Graph API as such allows you to easily access all public information about an object. The Graph API presents a simple, consistent view of the Facebook social graph and every object in the social graph has a unique ID. You can access the properties of an object by requesting https://graph.facebook.com/ID or https://graph.facebook.com/username.
 
For example, the username of the authorcode Facebook page is ‘authorcode’, so you can fetch the object at https://graph.facebook.com/authorcode.
 
We can also use the Facebook Graph api in c#.
 
Suppose if you want to get the total numbers of likes of your Facebook page, you can use the following code sample:

   private void GetCountLikes()
    {
        int number_of_likes = 0;
        object value = "";
        string url = "https://graph.facebook.com/authorcode";
        try
        {
            string jsonString = new System.Net.WebClient().DownloadString("https://graph.facebook.com/authorcode");
            System.Web.Script.Serialization.JavaScriptSerializer obj1 = new System.Web.Script.Serialization.JavaScriptSerializer();
            Dictionary<string, object> objDic = (Dictionary<string, object>)obj1.Deserialize<object>(jsonString);
            bool success = false;
            success = objDic.TryGetValue("likes", out value);
            if (success)
            {
                number_of_likes = (int)value;
            }
        }
        catch
        {
 
        }
    }

 
API provides us the information in JSON object so we are using System.Web.Script.Serialization.JavaScriptSerializer.Deserialize() function to get the information in efficient way.

How to identify the type of Object or the Class at runtime in C#

Runtime type identification of any object is useful for many reason such as when you need to casting of the objects or when you use the base class, you can get the what type of the object is being referred to by a base class reference. Another is when you need to perform various operation according to type of object. Continue reading How to identify the type of Object or the Class at runtime in C#