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.Task
1.get_Result()
at LinqToTwitter.TwitterQueryable1.GetEnumerator()
at System.Collections.Generic.List
1..ctor(IEnumerable1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable
1 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;
}
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();