Let Sitefinity Do The Hard Work And Post to Twitter For You

Craig Holdheide  |  Sep 08, 2014  |  Comments

When I started this blog, I wanted to try and automate as much as possible, hopefully to save me time and make it easier to maintain.  To be truthful, I was considering WordPress as my blogging platform at one time because of the awesome community around it.

I don't want to get into a debate about which blogging platform is better or why I decided on Sitefinity, but the truth was WordPress has a ton of great extensions.  One of the extensions that I really liked was the ability to post to Twitter when a blog post went live.

So I started snooping around Sitefinity looking for an easy way to post content from my blog to Twitter.  The solution I came up with is actually really simple and requires no code.  I also created a short video below and provided the exact instructions on how you can also set it up on your blog.

Also, I didn't mention this in the video, but you can apply this same concept to almost any other module in Sitefinity.  For example, you could set this up for the events module and every time a new event goes live on the Internet, it will also post to your corporate Twitter page.  Nice.

Anyways, enough chatter, get all the details below and enjoy.

Configure Twitter in Sitefinity

First, you need to configure Sitefinity with your Twitter account.  You will need to be part of the Administrators role in Sitefinity to complete these steps.

  1. Log on to Sitefinity back-end.
  2. Go to Administration > Settings.  If the multi-site module is enabled you will need to click on the Global Settings link.
  3. Click the Twitter menu item on the left.
  4. Under the section "Added Twitter applications", click the Actions menu and select the "Associate Twitter User".

    Associate Twitter User

  5. If you need to, log on to Twitter, and then click the "Authorize app" button.  After a few seconds you will return to the Twitter settings page and your Sitefinity account will be associated in Sitefinity.

    Twitter App Authorization

Create the Twitter Post Field

Next, you will create a separate field for the blog post content type to post on Twitter.  This step isn't required because you could just as easily post the "Title" to your Twitter feed, but I wanted to have more control over what message was getting posted.

  1. Go to Content > Blogs.
  2. Click on any one of the blogs listed.  If there are no blogs listed, create a new blog.
  3. Click the link "Custom Field for posts" under Settings for blogs.  You will need at least one blog post created before the links will be available via on the right.
  4. Under the section labeled "Custom fields" click the "Add a field..." button.

    Blog Posts Data Fields

  5. On the "Add a field" dialog set the following attributes and click continue.
    1. Type: Short text
    2. Name: TwitterPost
    3. This is a hidden field: unchecked
    4. Interface widget for entering data: Textbox
    5. DB Length: 140
    6. Allow empty values: checked
    7. Include in indexes: unchecked

      Add a blog post field
  6. Set the additional settings for the new Twitter Post field.
    1. Label: Twitter Post
    2. Instructional text: The tweet must be 140 characters or less.  This includes the content plus the link.
    3. Make required: checked
    4. Range Min: 1 characters
    5. Range Max: 124 characters

      Capture-5
  7. Click the Done button to add the new field to the blog posts content type.

You might be wondering why I set the  Max number of characters to 124 and not 140 characters.  This is because bit.ly will create shortened links about 14 characters long, but I am adding 1 additional character just in case 15 characters links are used and 1 character for a space.  140 minus 16 is 124 characters for content and 16 for the shorten link.

Configure the Twitter Post Feed

Now you just need to configure the Alternative Publishing settings to push the content out to Twitter.  This part gets a little confusing so I broke it up into four sections.

Set Basic Settings

  1. On the Sitefinity back-end, go to Administration > Alternative Publishing.
  2. On the Feeds & Notifications screen click the "Create a feed" button.
  3. On the Create a feed screen set the Title to "Tweet Blog Posts on Twitter"
  4. Check the box labeled "This feed is Active"

    Create a feed

 Set Advanced Options

  1. Under Advanced options click the button "Change Data structure..." under the Data section.
  2. Click the "Add a data field" button
  3. Set the Title and Name fields to "TwitterPost".  This is the same field name you used for custom field you created for the blog post.
  4. Set the Max length field to 140
  5. Click the "Save changes" button.
  6. On the "Create a feed " screen under Advanced options set the Feed type to "Pass through".

    Add to the data structure

Set the Content to Include

  1. Under "Content to include" remove any existing content types and then click "Add another content type" and set the following settings.
  2. Select "Sitefinity content" to include.
  3. Set the content type to "Blog Posts"
  4. Which blog posts to display?: From all blogs (this is up to you what you want to include)
  5. Set "Page where the content is published" to the main page that will be displaying your blog posts.
  6. Set the the Mappings, click the "Mapping Settings" button.
  7. Look for the new you added to your data structure, in this case we called it "TwitterPost", click the link "Add a mapping".
  8. In the drop down box select the field from the blog post content type, in the case it is called "Twitter Post".
  9. The click the "Accept changes" button and then click the "Done" button in the Content to include screen.

    Map Twitter Post Field

Set the Publish As Settings

  1. Under "Publish as..." remove any existing content types and then click "Add more..."
  2. Click Twitter feed open to publish too.
  3. Under the section labeled "Which Twitter application to use?" select the twitter application you configured earlier, in this case it was called "Sitefinity".
  4. Under the section labeled "Which Twitter user to use?" select the Twitter account you associate to Sitefinity, in this case my account name is "codeengagett".
  5. Click the button labeled "Mapping Settings".  This is where you will specify the content and link for the tweet.
  6. Set the field "Content" to your Twitter post field.  In my case it is called "TwitterPost".

    Map Twitter Post to Twitter Publishing Point

  7. Leave the Link field to its default and click the "Accept changes" button and then click the "Done" button in the Content to include screen.

    Twitter User Mapping

  8. Finally, click the "Save changes" button in the "Create a feed" screen to active the new feed.

Setup bit.ly URL Shortening 

Finally, if you haven't done so already, I highly suggest setting up bit.ly URL shortening so that you can shorten all your URLs for Twitter.  This will save you characters since you only have 140 them in total for each post.  Also, setting up bit.ly gives you one other benefit, tracking URL clicks for the shortened URLs.  Below are the general steps that can help you get this setup quickly.

  1. Go to https://bitly.com an login.  If you don't have a bit.ly account, create one and login.
  2. In the upper right, click on your username and select the "Settings" menu item from the drop down menu.
  3. On the "Settings" page clicked the "Advanced" tab.
  4. Scroll down to the bottom of the page, under the section "Legacy API Key" copy the Login value and the API Key value.
  5. Login to your Sitefinity backend, then go to Administration > Settings.
  6. Click the "Twitter" menu item on the left.
  7. Under the section "URL Shortening" click the edit link.
  8. Set the Account Login and API Key, then click the Save button.  Now your links for Twitter will be shortened automatically.

Conclusion

Armed with this information, you can now post to Twitter directly from Sitefinity without writing a single line of code or adding any custom modules.  That's pretty darn cool and not even Word Press can do that without downloading a custom extension.

To conclude, I would like to ask, what kind of mash up do you think you could build with Sitefinity and Twitter?  I made some suggestions in this blog post, but I want to hear from you an if possible I would like to see what kind of solutions you have implemented.

Craig out :-)

Reference Links

comments powered by Disqus

My Social Channels

Keep Up To Date

What is this?