Geeks With Blogs

News
Joe Mayo

The Twitter Search API returns an XML Atom formatted feed. So, in LINQ to Twitter, I've created an Atom object, which I return when someone performs a search.  The problem with the results is that the ID of the Status is mangled with other information. To solve this problem, you need to extract the status ID from the number following the last colon of the ID from the search Entry.  Here's some code to show how it's done:

        private static void SearchAndUseStatusTwitterDemo(TwitterContext twitterCtx)
        {
            var queryResult =
                (from search in twitterCtx.Search
                 where search.Type == SearchType.Search &&
                       search.Query == "LINQ to Twitter"
                 select search)
                 .SingleOrDefault();

            foreach (var entry in queryResult.Entries)
            {
                var statusID = entry.ID.Substring(entry.ID.LastIndexOf(":") + 1);

                var status =
                    (from tweet in twitterCtx.Status
                     where tweet.Type == StatusType.Show &&
                           tweet.ID == statusID
                     select tweet)
                     .SingleOrDefault();

                Console.WriteLine(
                    "ID: {0}, User: {1}\nTweet: {2}\n",
                    status.ID, status.User.Name, status.Text);
            }
        }

In the example above, I grab the last index of a colon and add one to it so I don't pick up the colon in the results too. Then, I do a normal Status entity query of type Show, providing the extracted status ID of which status to get.

Posted on Monday, February 1, 2010 9:46 PM C# , Twitter , LINQ to Twitter | Back to top

Copyright © Joe Mayo | Powered by: GeeksWithBlogs.net