Views: 11258
Number of votes: 4
Average rating:

How to post to Twitter and Facebook from edit mode in EPiServer – SocialPing.

SocialPing is a project that enable posting directly from EPiServer to ALL your social networks like Twitter, Facebook and LinkedIn in one go.

I have experienced that more and more customers is asking for ways to integrate their social media networks to their CMS solutions. After some research I found a lot of blog entries on how to build your own Twitter Workflow, how to build a gadget for reading updates from Facebook and Twitter but I couldn't find a way to publish to ALL my social networks. This was my motivation when I started working on a project that allows you to publish messages to all your social networks directly from EPiServer. The list currently contains 36 different networks – including Twitter, Facebook and LinkedIn.

SocialPing (which is included as a reference in your EPiServer project) uses services from Ping.fm to update your status on your social media networks. Ping.fm provides several ways to update your status. This project uses the email service to do the update.

 

You can download the source code for the project here:

SocialPing page on EPiCode.

 

Configuration:

1. Create your account on Ping.fm

After signing up, you have to assign the different social networks you want to hook your Ping.fm account to. The list contains 36 different social networks to choose from (Twitter, Facebook, LinkedIn, MySpace etc).

image

2. Grab your private Ping.fm email address

After assigning different networks you have to grab your private Ping.fm email address. This email address is found under “Services/Tools” on the dashboard. You are going to use this email address in step 5 in this tutorial.

image

3. Add a new property in admin mode

Now we have to define what to publish to the social networks when publish pages. We create a new property “PublishSocialMediaString” (string) to page type “News item”. Add this property to all page types you want to publish to your networks. I recommend to create a new tab for this property – just to separate this from the page content.

image

 

4. Copy folder “SocialPing” to the root of your EPiServer project

The folder contains two files: “settings.config” and “log.txt”.

The project is available for download here.

 

 5. Modify “settings.config”

Modify mail server settings and property name you created in step 3.

 

Attribute Description
server

Mail server. Example: “smtp.gmail.com”

port

Mail server port. Example: “25”

username

Mail server username.

Example: “username@gmail.com”

password

Mail server password

toaddress

Recipient email address. Insert you Ping.fm private email address here (step 2). Example: “xxxxx@ping.fm”

fromaddress

Your email address. Usually the same as “username@gmail.com”

propertytopublish

Name of the property created in step 3. The value of this property is the status posted to networks.

“PublishSocialMediaString” is used in this example.

logexceptions

True or false. Writes exceptions to log.txt if set to true.

 

Config.settings should look like this:

<?xml version="1.0" encoding="utf-8" ?>
<settings>
  <socialping 
    server="smtp.google.com" 
    port="25" 
    username="myusername" 
    password="mypassword" 
    toaddress="xxxxxx@ping.fm" 
    fromaddress="myusername@mailserver.com"
    propertytopublish="PublishSocialMediaString"
    logexceptions="true" />
</settings>

 

 6. Change Web.config (optional)

Change delivery method for SMTP to network and not IIS:

<mailSettings>
     <smtp deliveryMethod="Network" />
</mailSettings>

 

 

7. Add reference to “SocialPing.dll” in your EPiServer project.

 

8. Modify Global file in your EPiServer project

Now we have to attach a new PageEventHandler in Global.asax.cs. In this example we call method PostMessage when a page is published:

 

using System.Web.Mail;
using SocialPing;
 
protected void Application_Start(Object sender, EventArgs e){
     DataFactory.Instance.PublishedPage += new PageEventHandler(Instance_PublishedPage);
}
 
static void Instance_PublishedPage(object sender, PageEventArgs e){
   StatusMessage statusMsg = new StatusMessage();
   statusMsg.PostMessage(e.Page);
}

(The project is now using EPiServers initialization system to do this process auto-magically. No need to change global.asax)

 

Finished!

We’re now able to publish directly from EPiServer. Just to demonstrate we create a new page (News item), set a value for “PublishSocialMediaString” and click “Save and Publish”.

image

And that’s it – your status is updated!

A short URL to your page is created and appended on the status message:

 

Twitter:

image

 

Facebook:

image 

 

LinkedIn:

image

 

About Ping.fm

Ping.fm is a free service which makes you update all your social networks in one go. Ping.fm offers a variety of ways to integrate and post to social networks. This article describes how to use ping.fm to update status messages using ping.fm’s mail service. SocialPing is a class library which includes methods for sending status messages to ping.fm. Ping.fm forwards the message to your social networks.

 

Known limitations and further enhances

- The project relies on Ping.fm and assumes that their services is up and running.

- Your status is updated every time you publish a page. So if you publish a page ten times, you will have ten status updates in your twitter account. This should be handled by the plug-in. Now you have to leave the text field blank if you don't want to publish. You should be able to check (with a status field) if the current page is already posted to Ping.fm.

- No character limitations. It doesn’t check number of characters before sending to Ping. The status messages should be limited to 140 characters (Twitter) including URL. A character counter should be visible in edit mode.

- No status message is displayed. The editor don’t know if the message was sent and updated in social networks.

- Current version uses txt-file for logging. Log4net should be used for logging.

- Next version should include methods for retrieving your last status messages by using API calls to Ping.fm.

- It should be possible to choose which network you want to post to. This version is posting to all networks registered with your Ping.fm account.

- It should be possible to turn on and off posting with config file.

- The plan is to create a epimodule for easier installation and setup.

 

Wiki

Read more about the project and download the source code on epicode.

 

Requirements

Runtime: EPiServer CMS 6, .NET 3.5

If you want to change and compile the source code: Visual Studio 2008 SP1.

 

Feedback

Your feedback is appreciated for further development of the project.

Feel free to contact me: stian.grepstad /at/ makingwaves.no

 

 

 

 

 

Sep 14, 2010

Guest
(By Guest, 9/21/2010 12:33:36 PM)

Cool stuff
/ Anders Hattestad

Jarle Friestad
(By Jarle Friestad, 9/21/2010 12:33:36 PM)

Good stuff Stian

I would how ever improve one thing. Instead of manually registering the published page event + send the StatusMessage in global.axax => Use EPiServers initialization system inside StatusPing.dll to do this process auto-magically. E.g

[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class StatusPingModule : IInitializableModule
{
public void Initialize(InitializationEngine context)
{
DataFactory.Instance.PublishedPage += Instance_PublishedPage;
}

static void Instance_PublishedPage(object sender, PageEventArgs e)
{
StatusMessage statusMsg = new StatusMessage();
statusMsg.PostMessage(e.Page);
}


public void Preload(string[] parameters)
{
}

public void Uninitialize(InitializationEngine context)
{
DataFactory.Instance.PublishedPage -= Instance_PublishedPage;
}
}

alexander
(By alexander, 9/21/2010 12:33:36 PM)

Great post Stian. Really looking forward to using this in a project.

Stian Grepstad
(By Stian Grepstad, 9/21/2010 12:33:36 PM)

Thanks for the feedback Jarle!
This is a great improvement to the project - it will make the setup even easier :)

I have now changed (and released) the source code so it now uses EPiServers initialization system inside StatusPing.dll.
No modifications to global.asax is necessary to make the plugin work now.

Lars Bodahl
(By Lars Bodahl, 9/21/2010 12:33:36 PM)

Good stuff :)

Please login to comment.