0
votes

If I do the following search through Twitter -

search term: "from:jack just setting up my twttr"

URL: https://twitter.com/search?q=from%3Ajack%20just%20setting%20up%20my%20twttr&src=typd

I am able to view the first Tweet ever on Twitter. I am wondering if this is possible programmatically using something like Linq2Twitter or Tweetinvi?

I have tried using Linq2Twitter like so -

TwitterContext twitterCtx = new TwitterContext(auth);

const int MaxSearchEntriesToReturn = 100;

string searchTerm = "from:jack just setting up my twttr";

            List<Status> searchResponse =

                (from search in twitterCtx.Search
                 where search.Type == SearchType.Search &&
                       search.Query == searchTerm &&
                       search.Count == MaxSearchEntriesToReturn &&
                       search.SinceID == 1
                 select search.Statuses)
                .SingleOrDefault();

However this is bringing back a count of zero Tweets in searchResponse, is this even possible? My guess would be that as this Tweet is ten years old the api restrictions simply do not allow you to go back this far without a third party fire-hose like Gnip?

1
Search API reliably returns tweets only of the last 7 days. Tweetinvi or LinqToTwitter won't be able to help you with this. As you mentioned you will have to use Gnip or another third party which stored this type of information.Linvi

1 Answers

0
votes

The Search API only goes back a couple weeks and isn't a comprehensive search engine. Rather, it only display's according to an undocumented Twitter relevance algorithm:

Twitter Search API

That said, your code won't work because LINQ to Twitter is async. You should re-write the query as:

        List<Status> searchResponse =
            await
            (from search in twitterCtx.Search
             where search.Type == SearchType.Search &&
                   search.Query == searchTerm &&
                   search.Count == MaxSearchEntriesToReturn &&
                   search.SinceID == 1
             select search.Statuses)
            .SingleOrDefaultAsync();

Because your SinceID is so early, you still might not receive those early results for reasons explained earlier. Notice the await keyword and "Async" suffix on SingleOrDefault. Once that's done, you need to make sure the entire call chain of your code is async.