Archive

Archive for the ‘C#’ Category

Show tweets including retweets from user with Linq2Twitter issue

May 16th, 2011

I came across a weird one this week.

I have been working on a brand new project at work and one of the user stories was about a Twitter “widget” with tweets from a specific user. It was specified that the user could be any user and didn’t need to be authenticated. This is how I implemented it:

var twitterContext = new TwitterContext();

var statusTweets = from tweet in twitterContext.Status
                   where tweet.Type == StatusType.User &&
                   tweet.ScreenName == username
                   select tweet;

Then the requirements changed to include retweets from the same user. I changed my code to this:

var twitterContext = new TwitterContext();

var statusTweets = from tweet in twitterContext.Status
                   where tweet.Type == StatusType.User &&
                   tweet.ScreenName == username &&
                   tweet.IncludeRetweets
                   select tweet;

But when doing that, nothing was being returned.

After a long time trying other approaches I finally found what the problem was. Because I use Resharper I was advised to write ‘tweet.IncludeRetweets == true’ as only ‘tweet.IncludeRetweets’ and that just didn’t work. You actually need to have ‘tweet.IncludeRetweets == true’.

So, here is the correct code to get tweets from a user including retweets without being authenticated:

var twitterContext = new TwitterContext();

var statusTweets = from tweet in twitterContext.Status
                   where tweet.Type == StatusType.User &&
                   tweet.ScreenName == username &&
                   tweet.IncludeRetweets == true
                   select tweet;

I hope someone will find this useful.

admin C#, Linq2Twitter

NAnt, NAntContrib and sln

June 22nd, 2010

When running a NAnt build for a project I am working on at the moment I got the following error:

“Failure scanning ‘{PathToNAnt.Contrib.Tasks.dll}’ for extensions. Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.”

This was obviously related to the NAntContrib <msbuild> task as per target below:

<target name=”devBuild” depends=”cleanDev” description=”">
<loadtasks assembly=”{PathToNAntContribTasksdll}” />
<msbuild project=”{SolutionFile.sln}” />
</target>

In the end, the problem was the version of NAntContribTasks.dll I was using (0.84). I downloaded 0.85 and pointed to it instead and life is beautiful again.

BonesBrigadier C# , , ,