BlogEngine to Twitter - Part 2

Published by on
Tags:

A couple of weeks ago I blogged about the BlogEngine to Twitter extension I had written. However since this time I have been playing around with it a noticed a small problem. I would write a post and publish it, but once published I would notice a small mistake. I would then edit the post and publish again. Both these publishes would send a tweet to twitter. If you noticed 2 or 3 mistakes you start to produce twitter spam and everyone you know starts to get annoyed. So I wanted to modify the extension so at the base of the Add Entry page I would have a check box that when checked would send a tweet when the item is published like so:



To get this working on your site is a very simple. We first need to add the check box to the Add Entry page. This can be found in /admin/pages/add_entry.aspx. Insert the checkbox after the other checkboxes like so (line 160)

  157       <td>

  158         <asp:CheckBox runat="server" ID="cbEnableComments" Text="<%$ Resources:labels, enableComments %>" Checked="true" TabIndex="14" />

  159         <asp:CheckBox runat="server" ID="cbPublish" Text="<%$ Resources:labels, publish %>" Checked="true" TabIndex="15" />

  160         <asp:CheckBox runat="server" ID="cbTwitter" Text="<%$ Resources:labels, twitterCheckbox %>" Checked="true" TabIndex="16" />

  161       </td>

Next we need to wire this into the save button click. Open the code behind page for the add entry page (add_entry.ascx.cs) and find the method btnSave_Click. Just after the validation check add line 194:

 

  188   private void btnSave_Click(object sender, EventArgs e)

  189   {

  190     if (!Page.IsValid)

  191       throw new InvalidOperationException("One or more validators are invalid.");

  192 

  193         //Twitter integration

  194         Twitter.SendTweet = cbTwitter.Checked;

Next open the labels.resx file found in /App_GlobalResources and add the entry"twitterCheckbox" with the value "Send as tweet".

All you need to do now is download the new Twitter.cs (3.01 kb) extension file and drop the new one into the Extension directory (/App_Code/Extensions) and you are good to go. Remember from now on a tweet won't be sent unless the "Send as tweet"  check box is checked. By default it is checked.

Happy blogging.

BlogEngine to Twitter

Published by on
Tags:

This post has been updated: BlogEngine To Twitter - Part 2

I wanted a simple way to send my new blog post straight to Twitter to inform my followers of new posts and updates. To achieve this I created a BlogEngine extension and used the work completed by the guys at Vertigo to send messages to twitter.

Download the source code (Twitter.cs (2.78 kb)) and place it in the /App_Code/Extensions directory of your site, ensure that you get the Vertigo source code a place the compiled version into your sites bin directory. There is some setup work required to get the Vertigo component to work, read the blog for details of how to do this.

You will also need to add the following resources to the labels.resx file or localize the settings for your region:

NameValue
twitterUser Twitter username
twitterPassword Twitter password
twitterUpdateText Updated blog post text
twitterNewText New blog post text
twitterHelp Use this page to set user access information and the text that will be sent to twitter. Twitter updates can only be 140 characters long. The update and new text can contain the following place holders: <ul><li>{0} - Post title</li><li>{1} - Absolute URL to post</li></ul>

Once you have setup the class in your site you will need to visit the Extensions page and configure the Twitter extension from the extensions page: 



You should see the following configuration section:

 



Fill in the details and you should be good to go. If you have any problems add a comment to the end of this blog and I will try to help.


 

All blogs tagged with 'twitter'

Projects

Have you read?

SharePoint Unsecured Application Page



Blogs by date