Search code examples
c#linq-to-twitter

Linq2Twitter search missing protected tweets


I'm using Linq2Twitter and want to get all tweets with a certain hashtag from any public tweets and any protected tweet of someone I follow. I have setup my connection using a SingleUserAuthorizer, using my consumer key, secret, access token and access token secret. I am able to get any public tweet, however I'm not getting back any protected tweets from people that I follow.

I have the following setup in a loop to keep fetching more results. I get plenty of public tweets, including from my public test account, but from my protected test account I don't get anything.

search = await (twitterCtx.Search.Where(srch => srch.Type == SearchType.Search 
                                                                && srch.Count == 100 
                                                                && srch.Query == "#myHastTag"
                                                                && srch.MaxID == minID
                                                                && srch.ResultType == ResultType.Recent
                                                            )
                                                    .Select(srch => srch))
                                                    .SingleOrDefaultAsync();

I have tried looping through and getting more results (using srch.MaxID) when doing the search, but I can't find my tweet in the results.

If I use the exact same authentication but search for my user that has the protected tweet then I do get the response back:

search = await (twitterCtx.Status.Where(t => t.Type == StatusType.User
                                                                && t.UserID == myTwitterUserID
                                                            )
                                                    .Select(t => t))
                                                    .ToListAsync();

How can I get protected tweets to be included when searching for results?


Solution

  • I just read https://support.twitter.com/articles/14016 - I'm guessing that unless the user authorizes my app I'm not going to be able to get their tweets if their account is protected.

    Workaround: So far the best I've come up with is to query the users Home Timeline and then filter that by HashTag. If you mix that list with the list of public posts then you should have all of them:

    using (var twitterCtx = new TwitterContext(auth))
                {
                    var tweets =
                    await
                    (from tweet in twitterCtx.Status
                     where tweet.Type == StatusType.Home
                     && tweet.TweetMode == TweetMode.Extended
                     select tweet)
                    .ToListAsync();
    
                    var filteredTweets = tweets.Where(t => t.Entities.HashTagEntities.Any(h => h.Tag == "GregsTestWall"));
    
                }