Umbraco 6

The package for Umbraco 6 is no longer actively maintained, but you can still download the package from the Umbraco Our website.

Umbraco 6

Example macro

The example below shows how to create a feed of both Facebook posts and Instagram media. The ISocialTimelineEntry lets you sort the items by their creation date so the newest item is showed first (or last).

@inherits umbraco.MacroEngines.DynamicNodeContext
     
@using Skybrud.Social.Interfaces
@using Skybrud.Social.Facebook.Objects
@using Skybrud.Social.Instagram.Objects
@using Skybrud.Social.Umbraco.DataTypes.Facebook
@using Skybrud.Social.Umbraco.DataTypes.Instagram
 
@try{
     
    // Use a common type so that we can sort the entries by their date
    List<ISocialTimelineEntry> entries = new List<ISocialTimelineEntry>();
     
    // Gather posts from Facebook
    if (Model.HasValue("facebook")) {
        var oauth = FacebookOAuthDataValue.ParseXml(Model.facebook);
        if (oauth.HasData) {
            foreach (var post in oauth.GetService().GetPosts(oauth.Id).Data) {
                entries.Add(post);
            }
        }
    }
     
    // Gather images from Instagram
    if (Model.HasValue("instagram")) {
        var oauth = InstagramOAuthDataValue.ParseXml(Model.instagram);
        if (oauth.HasData) {
            foreach (var image in oauth.GetService().Endpoints.Users.GetMedia().Images) {
                entries.Add(image);
            }
        }
    }
     
    if (entries.Count == 0) {
     
        <div>OH NOES! No entries!!!</div>
     
    } else {
         
        <div id="entries">
     
        // List the entries by their date - showing the newest first
        @foreach (var entry in entries.OrderByDescending(x => x.SortDate)) {
             
            FacebookPostSummary post = entry as FacebookPostSummary;
            InstagramImage image = entry as InstagramImage;
             
            if (post != null) {
                <div class="item facebook post">@post.Message</div>
            } else if (image != null) {
                <div class="item instagram image"><img src="@image.LowRes" width="306" height="306" /></div>
            }
         
        }
         
        </div>
     
    }
     
} catch (Exception ex) {
 
    // Obviously it's bad to write out exception details on a live site
     
    //<div>@ex.Message</div>
         
    <div>Ooops! Something went wrong.</div>
 
}