Status.Retweet object for Retweet Freature

Nov 23, 2009 at 4:09 PM

Currently Status.Retweet object returns null when a user retweets a status. I found that in home timeline response twitter adds "retweeted_status" element.  The "ProcessResults" method defined in "StatusRequestProcessor.cs" looks for "retweet_details" element. I modified the method which now looks like this

public IList ProcessResults(XElement twitterResponse)
        {
            var responseItems = twitterResponse.Elements("status").ToList();

            // if we get only a single response back,
            // such as a Show request, make sure we get it
            if (twitterResponse.Name == "status")
            {
                responseItems.Add(twitterResponse);
            }

            var usr = new User();

            var statusList =
                from status in responseItems
                let dateParts =
                    status.Element("created_at").Value.Split(' ')
                let createdAtDate =
                    DateTime.Parse(
                        string.Format("{0} {1} {2} {3} GMT",
                        dateParts[1],
                        dateParts[2],
                        dateParts[5],
                        dateParts[3]),
                        CultureInfo.InvariantCulture)
                let user = status.Element("user")
                let retweet = status.Element("retweeted_status")
                let rtDateParts =
                    retweet == null ?
                        null :
                        retweet.Element("created_at").Value.Split(' ')
                let retweetedAtDate =
                    retweet == null ?
                        DateTime.MinValue :
                        DateTime.Parse(
                            string.Format("{0} {1} {2} {3} GMT",
                            rtDateParts[1],
                            rtDateParts[2],
                            rtDateParts[5],
                            rtDateParts[3]),
                            CultureInfo.InvariantCulture)
                select
                   new Status
                   {
                       Type = Type,
                       ID = ID,
                       UserID = UserID,
                       ScreenName = ScreenName,
                       Page = Page,
                       Count = Count,
                       MaxID = MaxID,
                       SinceID = SinceID,
                       CreatedAt = createdAtDate,
                       Favorited =
                        bool.Parse(
                            string.IsNullOrEmpty(status.Element("favorited").Value) ?
                            "true" :
                            status.Element("favorited").Value),
                       StatusID = status.Element("id").Value,
                       InReplyToStatusID = status.Element("in_reply_to_status_id").Value,
                       InReplyToUserID = status.Element("in_reply_to_user_id").Value,
                       Source = status.Element("source").Value,
                       Text = (retweet == null)?status.Element("text").Value:retweet.Element("text").Value,
                       Truncated = bool.Parse(status.Element("truncated").Value),
                       InReplyToScreenName =
                            status.Element("in_reply_to_screen_name") == null ?
                                string.Empty :
                                status.Element("in_reply_to_screen_name").Value,
                       User = usr.CreateUser(user),
                       Retweet =
                           retweet == null ?
                               null :
                               new Retweet
                               {
                                   ID = retweet.Element("id").Value,
                                   RetweetedAt = retweetedAtDate,
                                   RetweetingUser = usr.CreateUser(retweet.Element("user"))
                               }
                   };

            return statusList.ToList();
        }

Now it fills the status.Retweet object. Please advise this approach is correct.

Thank you

 

 

 

Coordinator
Nov 24, 2009 at 4:26 AM

Thanks Ajay,

That was it.  Twitter also changed some other items, so I updated to accommodate all these changes and released a new v2.0.5.2.

Joe