Instagram Getting information about a location

Getting information about a location

The GetLocation method lets you request information about a given location based on the ID of the location.

@using Skybrud.Social.Instagram.Objects.Locations
@using Skybrud.Social.Instagram.Responses.Locations
@inherits WebViewPage<Skybrud.Social.Instagram.InstagramService>

@{

    // Request information about a specific location (in this case our offices at Skybrud.dk)
    InstagramGetLocationResponse response = Model.Locations.GetLocation(241201111);

    // Get the location from the response
    InstagramLocation location = response.Body.Data;

    // Print some information about the location
    <p>ID: @location.Id</p>
    <p>Name: @location.Name</p>
    <p>Latitude: @location.Latitude</p>
    <p>Longitude: @location.Longitude</p>

}

A location in Skybrud.Social is represented by the InstagramLocation class, which you can check out for further information. However a location in the Instagram API only consists of very basic information, so you will only be able to get the ID and name as well as the latitude and longitude of the location.

Error handling

When making requests to the Instagram API, you may occasionally experience that the API will response with an error. In Skybrud.Social, errors returned by the Instagram API will trigger an exception.

Specifically for the GetLocation method, if you're trying to request information about a location that doesn't exist, the Instagram API will respond with an error, which in return will trigger an exception of the type InstagramHttpNotFoundException.

@using Skybrud.Social.Instagram.Exceptions
@using Skybrud.Social.Instagram.Objects.Locations
@using Skybrud.Social.Instagram.Responses.Locations
@inherits WebViewPage<Skybrud.Social.Instagram.InstagramService>

@{


    try {

        // Request information about a non-existing location
        InstagramGetLocationResponse response = Model.Locations.GetLocation(0);

        // Get the location from the response
        InstagramLocation location = response.Body.Data;

        // Print some information about the location
        <p>ID: @location.Id</p>
        <p>Name: @location.Name</p>
        <p>Latitude: @location.Latitude</p>
        <p>Longitude: @location.Longitude</p>

    } catch (InstagramHttpNotFoundException) {

        <div class="alert alert-danger">The requested location does not exist.</div>

    } catch (Exception) {

        <div class="alert alert-danger">Oh noes. Something bad happened.</div>

    }

}

The Instagram API may also respond with other types of errors, so it is recommended to see the page about (error handling)[({localLink:2330}) for further information.