Umbraco 7

Umbraco 7

Skybrud.Social for Umbraco 7 is a package that targets the backoffice of Umbraco. In its current form, the package adds data types for OAuth authentication with Facebook, Twitter, Instagram and Google. Authentication with one of the mentioned services then lets you interact with and make calls to the corresponding API - eg. to shows your Facebook posts or Instagram images on your website.

If you're instead looking for something to let members of your Umbraco site login using one of the mentioned services, you should have a look at Skybrud.Social in general, as it is out of the scope of this Umbraco package.

Installation

There are a few ways to install this package. If you're already using Visual Studio, it is recommended to install this package via NuGet.

  1. NuGet Package
    Install this NuGet package in your Visual Studio project. Makes updating easy.

  2. Umbraco package
    Install this Umbraco package via the developer section in Umbraco.

  3. ZIP file
    Manually unzip and move files to the root directory of your website.

Found a bug? Having any issues?

I you have found a bug, have an issue or just have a question in general, feel free to create an issue on the issue tracker on GitHub.

Notice that Skybrud.Social has it's own repository and therefore also it's own issue tracker. If you're unsure where to create an issue, just post it on one of the issue trackers, and I'll get back to you ;)

As this is an Umbraco package, you're also more than welcome to ask questions in the forum at our.umbraco.org.

Changelog

If you want to see what has changed in each version, a changelog is available on the list of releases on GitHub.

As there only have been two releases of this package so far, the list is however rather limited at the moment.

Facebook example

The example below shows how to fetch information about a given user as well as the most recent posts of a given user. The name me is reference to the authenticated user based on the OAuth data stored in the facebook property.

The name can be changed to a user ID to fetch information and posts of another user.

@using Skybrud.Social.Facebook
@using Skybrud.Social.Facebook.Objects.Posts
@using Skybrud.Social.Facebook.Objects.Users
@using Skybrud.Social.Facebook.Options.Posts
@using Skybrud.Social.Facebook.Responses.Posts
@using Skybrud.Social.Umbraco.Facebook.PropertyEditors.OAuth
@inherits Umbraco.Web.Mvc.UmbracoViewPage

@{

    // Get the OAuth information stored in the property
    FacebookOAuthData facebook = Model.GetPropertyValue("facebook") as FacebookOAuthData;

    // Check whether the OAuth data is valid
    if (facebook != null && facebook.IsValid) {

        // Gets an instance of FacebookService based on the OAuth data
        FacebookService service = facebook.GetService();

        // Get information about the authenticated user
        FacebookUser me = service.Users.GetUser("me").Body;

        <fieldset>
            <legend>Facebook</legend>
            <p>@me.Name (ID: @me.Id)</p>
        </fieldset>

        // Gets the most recent posts of the authenticated user (me)
        FacebookPostsResponse response = service.Posts.GetPosts(new FacebookGetPostsOptions {
            Identifier = "me",
            Fields = "id,name,message,story,created_time,picture,link,description",
            Limit = 25
        });

        foreach (FacebookPost post in response.Body.Data) {

            // Do something with each post

        }

    }

}

Twitter example

Something similar is possible with the Twitter API. Twitter doesn't have a reference to me like Facebook, but if you have authenticated with the Twitter property in the backoffice, we can just grab your user ID from there.

@using Skybrud.Social.Twitter
@using Skybrud.Social.Twitter.Objects
@using Skybrud.Social.Umbraco.Twitter.PropertyEditors.OAuth
@inherits Umbraco.Web.Mvc.UmbracoViewPage

@{

    // Get the OAuth information stored in the property
    TwitterOAuthData twitter = Model.GetPropertyValue("twitter") as TwitterOAuthData;

    // Check whether the OAuth data is valid
    if (twitter != null && twitter.IsValid) {

        // Gets an instance of TwitterService based on the OAuth data
        TwitterService service = twitter.GetService();

        // Get information about the authenticated user
        TwitterUser user = service.Users.GetUser(twitter.Id).Body;

        // Get recent status messages (tweets) from the authenticated user
        TwitterStatusMessage[] recent = service.Statuses.GetUserTimeline(user.Id).Body;

        <fieldset>
            <legend>Twitter</legend>
            <p>@user.Name (ID: @user.Id)</p>
            <hr />
            @foreach (TwitterStatusMessage status in recent) {
                <p>@status.Text</p>
            }
        </fieldset>

    }

}

Add properties on a global page

The two examples for Facebook and Twitter reads the property for the current page. In many scenarios, you might want to add the properties on a global page instead - eg. if you're to show recent tweets in a footer.

So rather than:

// Get the OAuth information stored in the property
TwitterOAuthData twitter = Model.GetPropertyValue("twitter") as TwitterOAuthData;

you can find the root page of your site - eg. the ancestor at level 1:

// Get the OAuth information stored in the property
TwitterOAuthData twitter = Model.AncestorOrSelf(1).GetPropertyValue("twitter") as TwitterOAuthData;