Instagram Media types
Instagram Platform API deprecation
As of April 4th, Instagram has suddenly decided to close down most of their Platform API. This unfortunately also means that many of the features in this package are no longer working. You can read more about the changes to the Instagram Platform API via the links below:

Platform Changelog

API and Other Platform Product Changes

Media types

In Skybrud.Social, an Instagram media is represented by an instance of the InstagramMedia class, which however is just a base class. As a media may be either a regular image, a video or a carousel (consisting of a combination of images and/or videos), these types are represented by the InstagramImage, InstagramVideo and InstagramCarousel classes respectively, all inheriting from the InstagramMedia class.

With the above in mind, we can check the actual type of an InstagramMedia instance - eg. as shown below:

@using Skybrud.Social.Instagram.Models.Media
@using Skybrud.Social.Instagram.Models.Media.Carousels
@using Skybrud.Social.Instagram.Models.Users
@using Skybrud.Social.Instagram.Responses.Users
@inherits WebViewPage<Skybrud.Social.Instagram.InstagramService>
@{

    // Make the request to the Instagram API
    InstagramGetUserRecentMediaResponse response = Model.Users.GetRecentMedia();

    // Get a reference to the response body
    InstagramGetUserRecentMediaEnvelope body = response.Body;

    // Iterate through the returned media
    foreach (InstagramMedia media in body.Data) {

        <pre>@media.CaptionText</pre>
        <pre>@media.Link</pre>

        InstagramVideo video;
        InstagramCarousel carousel;

        if (media.IsVideo(out video)) {

            <pre>@video.Videos.StandardResolution.Url</pre>

        } else if (media.IsCarousel(out carousel)) {

            foreach (var carouselMedia in carousel.CarouselMedia) {

                InstagramCarouselImage carouselImage;
                InstagramCarouselVideo carouselVideo;

                if (carouselMedia.IsImage(out carouselImage)) {

                    <pre>@carouselImage.Images.StandardResolution</pre>

                } else if (carouselMedia.IsVideo(out carouselVideo)) {

                    <pre>@carouselVideo.Videos.StandardResolution</pre>

                }

            }

        } else {

            <pre>@media.Images.StandardResolution</pre>

        }

    }

}