After messing around with uTwit and reading a lot of other posts, I finally managed to get it going.
The following script actually works, others have posted similar scripts, but they always seem to be missing something. You have to setup a twitter account and goto dev.twitter, setup an application, setup a callback url(can be anything, but needs to be there), generate auth details.
Few things to check, make sure you have installed the Uwit package datatype etc. Add the property for example to your homepage which is what I have done in this case called 'twitter'. You install using the .zip files, I didn't realise this at first, lol :D
The home node is the id that you will need to reference, I have tried to cover all bases here as I appreciate everyone has different uses and implementations. Hopefully this will all make sense. There are commented out lines should you need to hardcode or called a specific node id.
You will need to add the following references to you project:
Our.Umbraco.uTwit.DataType.dll
Our.Umbraco.uTwit.Web.dll
@inherits umbraco.MacroEngines.DynamicNodeContext
@using Our.Umbraco.uTwit
@using umbraco.NodeFactory
@{
const string twitterOAuthPropertyAlias = "twitter";
const int numberOfTweetsToDisplay = 3;
const bool includeReplies = false;
const bool includeRetweets = true;
// Get current node
Node home = umbraco.NodeFactory.Node.GetCurrent();
// Alternatively if you have a settings node for example use a specific id
//var home = Model.NodeById(1079);
// If you want to hard code the details then use this line
// string twitterOAuth = "{'ScreenName': 'xxx','OAuthToken': 'xxx','OAuthTokenSecret': 'xxx','ConsumerKey': 'xxx','ConsumerSecret': 'xxx'}";
string twitterOAuth = home.GetProperty
(twitterOAuthPropertyAlias);
// If you use a specific node ID then use this instead
//string twitterOAuth = home.GetPropertyValue(twitterOAuthPropertyAlias) as string();
var config = uTwit.DeserializeValue(twitterOAuth);
var tweets = uTwit.GetLatestTweets(config, numberOfTweetsToDisplay, includeReplies, includeRetweets);
if (tweets != null)
{
foreach (var tweet in tweets)
{
var tweetToDisplay = tweet.IsRetweet ? tweet.RetweetedStatus : tweet;
}
}
}
Hope this saved some of you some headaches when it wasn't working.
No comments:
Post a Comment