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>
@{
InstagramGetUserRecentMediaResponse response = Model.Users.GetRecentMedia();
InstagramGetUserRecentMediaEnvelope body = response.Body;
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>
}
}
}