Monday, September 20, 2010

Integrating twitter with SharePoint

Hi All,

Interesting integration with SharePoint has come. And yes, you have heard it right. It is the integration of twitter with SharePoint. We have done this for MOSS 2007. If this can be done with 2007 version of SharePoint, it certainly can be done in SPS 2010.

Before starting this topic, first we need to understand the structure of twitter XML file that we will be using in this post. We all know the so popular and ever increasing twitter site. So many people updates some or the other thing on twitter. In twitter they are called statuses.

If you already have an account in twitter or do not have, this XML file has no concern with this, because we can anyways see tweets of anybody even though you do not have account. This XML file read the latest tweet, followers, following and updates. Also shows your user name, photo, location, description and website. Well, actually you need to observe the XML file properly and from there you can get an idea about what all parameters you can retrieve.

For example, if I talk about my profile, malayvasavada, then I need to look for this XML file.{twitter user name}.xml

Open this XML in Internet explorer. (In Google chrome, it cannot display properly) And you can see similar to this.

So I get following XML file.

<?xml version="1.0" encoding="UTF-8" ?>
<name>Malay Vasavada</name>
<description />
<url />
<created_at>Wed Dec 30 07:43:33 +0000 2009</created_at>
<time_zone>New Delhi</time_zone>
<notifications />
<following />
<follow_request_sent />
<created_at>Sat Sep 18 04:01:32 +0000 2010</created_at>
<text>Silverlight 5? Hummm....something very good is coming to web. Keep watching.</text>
<in_reply_to_status_id />
<in_reply_to_user_id />
<in_reply_to_screen_name />
<retweet_count />
<geo />
<coordinates />
<place />
<contributors />

As you can see, from the XML, you can get so much information. Name, location, photo URL, even the background color of my twitter profile site, latest tweet, date and time of tweet. So now the point is how to use this XML file and how to present it in SharePoint.

Okay, let us go ahead and use XML web part that SharePoint provides. Create one web part page in any site under any document library. Click on add web part and then add XML web part. Now in the XML Web part, modify shared we part properties. In the XML link, provide the twitter XML file path. Click on Apply and Ok.

Now see what you have got.

You can see profile, latest tweet and followers and so on so forth. However, it is not formatted. It looks ugly. So we need to format this output. When we have XML file with us, the formatting options comes with XSLT files.

You can use Visual Studio to create XSLT file because Visual Studio gives you a fantastic UI to create and suggestions for the attribute and tags.

I have already created one XSLT file here. See below code. You can format according to your need. Just make sure that XML tag remains the same. You can change the layout in term of tables, td and tr, width and height.

<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="html" indent="yes" />
<xsl:template match="/user">
<style type="text/css">
.dsc{ font-weight:bold; vertical-align:top; text-align:left; } .prof { background-color:#
<xsl:value-of select="profile_background_color" />
; color:#
<xsl:value-of select="profile_text_color" />
; } .prof a { color:#
<xsl:value-of select="profile_link_color" />
; text-decoration:none; overflow:auto; }

<table width="100%" style="background-image:url({profile_background_image_url}); text-align:center;">

<td colspan="3" align="center">

<img src="" />




<td colspan="3" align="center">
<a href="{screen_name}" target="_blank">
<xsl:value-of select="screen_name" />
<img src="{profile_image_url}" />



<td align="center" colspan="3">
City: <xsl:value-of select="location" />



<td align="center" colspan="3">
Language: <xsl:value-of select="lang" />



<td align="center" colspan="3">
Status: <xsl:value-of select="status/text" />



<td align="center" colspan="3">
Last Status Created Date: <xsl:value-of select="status/created_at" />



Friends count: <xsl:value-of select="friends_count" />
Followers_count: <xsl:value-of select="followers_count" />
Statuses_count: <xsl:value-of select="statuses_count" />




Open XSL editor in the web part property. Copy and paste the above XML file. Just make sure that the first line has to be at first column, first row area. Exactly at the top of the window and left corner, otherwise you will get an error. "The XSL specified by the XSL property or XSL Link property is not valid, or the XSL file cannot be accessed. Make…..". You might stretch your head whole day finding what went wrong.

And this is the overall result combining XML and XSLT. You have just integrated twitter with SharePoint. Cool, isn’t it?

1 comment:

Mikado said...

Great article! I just wanted to say that there is also an easy way - buy a Twitter web part and integrate it with SharePoint:

Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to