How To: Determine if a Tweet is Favorited or Retweeted

Apr 13, 2011 at 4:51 PM

I received email from someone asking a similar question and decided to post this here in case it would be helpful.

First, you need to get the tweet you're interested in.  To get a specific tweet, use the Show type of the Status entity, like this:

            var statusResult = 
                (from status in twitterCtx.Status
                 where status.Type == StatusType.Show &&
                       status.ID == tweet.StatusID

In the code above, tweet is a parameter that was passed into a method or obtained somewhere else.  I'm reading from the StatusID, which is returned from Twitter, but assigning to ID, which is the input for the query.  This tidbit is confusing and dates back to when I originally began LINQ to Twitter.  My thought pattern at the time was that I needed to provide a way to separate the input from the output so you can verify exactly what Twitter is sending back (StatusID) as opposed to what you sent in (ID).  Whether this is good or not could be a topic of discussion and I welcome any comments or suggestions on what would be better.

Note: You should anticipate and write error handling code for situations where the tweet isn't found, Twitter is down, etc.

Once you have the status queried, you can get the details of the tweet, like this:

            bool favorited = false;
            bool retweeted = false;

            if (statusResult != null)
                favorited = statusResult.Favorited;
                retweeted = (bool)statusResult.Retweeted;

This example shows how to use the Favorited and Retweeted properties to obtain the results.  Since Twitter's implementation of Retweeted and Retweet count have been unpredictable, their types are currently object.  That might change later and Retweeted might become a bool when it's more mature.  Currently, Twitter's implementation of Retweet and Retweet count is broken, as documented in Issue #2141.


Apr 13, 2011 at 6:38 PM

Works fine with Favorited property, but not so fine with Retweeted. Retweeted property is always set to false. Why?

Apr 13, 2011 at 7:01 PM


There's a bug in Twitter's implementation of Retweeted and Retweet Count.  The last sentence of my previous post contains the link to the details.