1

I am using the LinqToTwitter API and have the following problem.

How can I get the information if I (the current user) have already retweeted a tweet though I can change the IsChecked Property on the ToggleButton for Retweet.

I've already tried to get all tweets of one single Status to compare it with a List of tweetIDs which I've retweeted.

var publicTweets = await (from tweet in TweetContent.Connection.Status
                          where tweet.Type == StatusType.Retweets &&
                                tweet.ID == TweetID
                          select tweet)
                          .ToListAsync();

foreach (var publicTweet in publicTweets)
{
    foreach (var myTweet in TweetContent.AllMyReTweets)
    {
        if (publicTweet.ID == myTweet)
        {
            // false means the ToggleButton is PreSet
            RetweetState = false;
            break;
        }
    }
}
// No hit
RetweetState = true;

And the TweetContent.AllMyRetweets is defined here:

 List<ulong> myList = new List<ulong>();
 var myRetweets = await (from retweet in TweetContent.Connection.Status
                         where retweet.Type == StatusType.RetweetsOfMe &&
                               retweet.Count == 100
                         select retweet)
                         .ToListAsync();

if (myRetweets != null)
{
    foreach (var tweet in myRetweets)
    {
        myList.Add(tweet.ID);
    }
}

I think this solution has two problems:

  1. It makes one API call for each tweet I want to display which means it can need a lot of time.

  2. I'll very quickly get a "Rate Limit exceeded" exception which tells me that this can't be the right way to do it.

What is the best way to do this?

Ivar
  • 6,138
  • 12
  • 49
  • 61
Ulpin
  • 179
  • 1
  • 14

1 Answers1

1

This was more easy than I thought :-)

The information is in every Status in the property Status.Retweeted but it is not filled after a default searh query like:

 var tweets = Enumerable.FirstOrDefault(
                                from tweet in TweetContent.Connection.Search
                                where tweet.Type == SearchType.Search &&
                                    tweet.Query == query &&
                                    tweet.IncludeEntities == true &&
                                    tweet.Count == maxNumberToFind && (tweet.MaxID == id)
                                select tweet);

After this you have to make a lookUp query with the tweetIDList you just received. This will fill the property Status.Retweeted with the right value.

        List<Status> tweets =
        await
        (from tweet in TweetContent.Connection.Status
         where tweet.Type == StatusType.Lookup &&
               tweet.TweetIDs == tweetIDList
         select tweet)
        .ToListAsync();

        return tweets;
Ulpin
  • 179
  • 1
  • 14