Search Wiki:
Project Description

This extension displays last twitter updates on your BlogEngine.NET blog. (source code only)
Cette extension affiche les dernières mises à jour de Twitter sur votre blog BlogEngine.NET.

twitter.png

Demo : http://www.net4wam.com

Prerequisites
BlogEngine.NET 1.3 (1.2 ?)

How To

1. Download source code. Put the Twitter.cs file in App_Code/Controls folder of your BlogEngine.NET site.
1. Télécharger le code source. Copier le fichier Twitter.cs dans le dossier App_Code/Controls de votre site BlogEngine.NET.

2. Add the following line in the page where the control should appear.
2. Ajouter la ligne suivante dans la page où le contrôle doit s'afficher.

<blog:Twitter ID="Twitter" runat="server" Username="julesss" Password="mypassword" />

Properties

- Username (required) : username of your Twitter account
- Password (required) : password of your Twitter account
- Timeline (optionnal) : updates type to display from Twitter : User, Friends or Public (default : User)
- NumberOfStatuses (optionnal) : number of updates to display (default : 20, which is the maximum recommended by Twitter)
Last edited Jan 23 at 2:18 PM  by net4wam, version 3
Comments
cheetahtech wrote  Mar 9 at 10:18 PM  
I added and changed a few lines. This will allow the user to put how long ago twitter was updated.

I started at line 141 of the source.

string innerText = "\"" + status["text"].InnerText + "\"" + "<br />" + "<a href='http://twitter.com/" + status["user"]["screen_name"].InnerText + "/statuses/" + status["id"].InnerText + "/'>";

string TwitterTime = status["created_at"].InnerText;
string[] TimeValues = TwitterTime.Split(' ');
TwitterTime = TimeValues[1] + " " + TimeValues[2] + " " + TimeValues[5] + " " + TimeValues[3] + " GMT";
DateTime dt = Convert.ToDateTime(TwitterTime);
innerText += GetRelativeDate(dt);
innerText += "</a>";

// Conversion of url in link
//Regex regex = new Regex(@"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?");
//MatchCollection matches = regex.Matches(innerText);
//foreach (Match match in matches)
//{
// innerText = innerText.Replace(match.Value, string.Format(link, match.Value, match.Value));
//}


/// <summary>
/// gets the relevant time of the current twitter user.
/// </summary>
/// <param name="date"></param>
/// <returns></returns>
private String GetRelativeDate(DateTime date)
{
DateTime now = DateTime.Now;
TimeSpan span = now - date;
if (span <= TimeSpan.FromSeconds(60))
{
return span.Seconds + " seconds ago";
}
else if (span <= TimeSpan.FromMinutes(60))
{
if (span.Minutes > 1)
{
return "about " + span.Minutes + " minutes ago";
}
else
{
return "about a minute ago";
}
}
else if (span <= TimeSpan.FromHours(24))
{
if (span.Hours > 1)
{
return "about " + span.Hours + " hours ago";
}
else
{
return "about an hour ago";
}
}
else
{
if (span.Days > 1)
{
return "about " + span.Days + "days ago";
}
else
{
return "about a day ago";
}
}
}

Updating...