Facebook Getting information about an application

Getting information about an application

If you need to get information about a given Facebook application (app), you can use the GetApplication method in the applications endpoint. In it's simplest form, you can use the method like shown below:

@using Skybrud.Social.Facebook.Models.Applications
@using Skybrud.Social.Facebook.Responses.Applications
@inherits WebViewPage<Skybrud.Social.Facebook.FacebookService>
              
@{

    // Get information about Facebook's "Graph API Explorer" app
    FacebookGetApplicationResponse response = Model.Applications.GetApplication("145634995501895");

    // Get a reference to the application
    FacebookApplication application = response.Body;

    <pre>ID: @application.Id</pre>
    <pre>Name: @application.Name</pre>

}

In this example, 145634995501895is the ID of Facebook's own Graph API Explorer app.

Fields to be returned by the API

Like other responses from the Facebook Graph API, a response with information about an application will only contain a few fields by default. For an application, this will be the id, name, link and category fields (or the Id, Name, Link and Category properties when mapped in Skybrud.Social).

To request specific fields from the API, you can specify an instance of FacebookFieldsCollection as the second parameter for the GetApplication method:

@using Skybrud.Social.Facebook.Constants
@using Skybrud.Social.Facebook.Fields
@using Skybrud.Social.Facebook.Models.Applications
@using Skybrud.Social.Facebook.Responses.Applications
@inherits WebViewPage<Skybrud.Social.Facebook.FacebookService>

@{
    
    // Declare the fields to be returned by the Graph API
    FacebookFieldsCollection fields = new FacebookFieldsCollection {
        FacebookApplicationFields.Id,
        FacebookApplicationFields.AppName,
        FacebookApplicationFields.Description,
        FacebookApplicationFields.Namespace
    };

    // Get information about Facebook's "Graph API Explorer" app
    FacebookGetApplicationResponse response = Model.Applications.GetApplication("198111253569705", fields);

    // Get a reference to the application
    FacebookApplication application = response.Body;

    <pre>ID: @application.Id</pre>
    <pre>Name: @application.Name</pre>
    <pre>App name: @application.AppName</pre>
    <pre>Description: @application.Description</pre>
    <pre>Namespace: @application.Namespace</pre>

}

There are a number of different ways to initialize an instance of FacebookFieldsCollection, so try have a look at the fields page for more information. Like shown above, the FacebookApplicationFields class also provides constants for known fields/properties of an application.