1

I made a method to return a list of tweets given their IDs using LinqToTwitter but I get this error message when query is performed:

"An item with the same key has already been added."

StackTrace:

at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification) at System.Threading.Tasks.Task1.get_Result() at LinqToTwitter.TwitterQueryable1.GetEnumerator() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)

Here is my code:

private IList<Tweet> GetTweets()
{
   TwitterContext ctx = new TwitterContext(this.CrateAuth());
   IList<Tweet> tweets = new List<Tweet>();

   var foundTweets =
   (from tweet in ctx.Status
    where tweet.Type == StatusType.Show &&
    (tweet.ID == 522564774706831362 || tweet.ID == 522922846293884929)
         select tweet).ToList();

    foreach (var tweet in foundTweets)
    {
        tweets.Add(
            new Tweet
            {
                ImageUrl = tweet.User.ProfileImageUrl,
                ScreenName = tweet.User.ScreenNameResponse,
                Text = tweet.Text,
                Date = tweet.CreatedAt
            });
    }

    return tweets;
}
Luis
  • 41
  • 4

2 Answers2

2

I realized that I need StatusType.Lookup instead of StatusType.Show. My query should be:

var foundTweets =
(from tweet in ctx.Status
 where tweet.Type == StatusType.Lookup &&
       tweet.TweetIDs == "522564774706831362,522922846293884929"
 select tweet).ToList();
Luis
  • 41
  • 4
1

The StatusType.Show query only accepts a single ID. Also, LINQ to Twitter doesn't recognize the || operator since Property/Value pairs are && together to form URL query parameters in the underlying implementation. As mentioned in your follow-up answer, the StatusType.Lookup is a better approach.

Joe Mayo
  • 7,501
  • 7
  • 41
  • 60
  • I need to work with .net framework 4.0 and, as a consequence, with LinqToTwitter 2.1.11. Can I use LoookUp with that version? Could I implement a request of tweets by a list of IDs? – Luis Oct 24 '14 at 03:04
  • StatusType.Lookup is a newer API and wasn't available in the 2.1.x timeframe. That said, I anticipated the potential for either new APIs that I haven't implemented or older versions that didn't have a newer API and created Raw queries and commands. Here's the URL for documentation on Raw queries: https://linqtotwitter.codeplex.com/wikipage?title=Raw%20Queries&referringTitle=Safety%20Hatch and here's the Twitter API docs for statuses/lookup: https://dev.twitter.com/rest/reference/get/statuses/lookup – Joe Mayo Oct 24 '14 at 03:58
  • Last February, I made some late bug fixes to 2.1.12 that weren't deployed to NuGet, but you can download here: https://linqtotwitter.codeplex.com/releases/view/118031 – Joe Mayo Oct 24 '14 at 04:03