Search code examples
c#twitterlinq-to-twitter

C# - LINQ to Twitter - Read twitter landing page without login


I just started making a application that uses information from twitter. I want to get the posts that are available on the Twitter landing page when no user is logged in. This page shows public posts that might be relevant to your geo location. Is it possible to get these posts using LinqToTwitter without logging in a user?


Solution

  • Authentication without user context

    As per my comment, this is called application-only authentication, and the documentation of LinqToTwitter about it actually mentions this answer of Joe Mayo that I've already suggested you to follow.

    Geolocation

    Finally, look at this doc for the GeoCode: something like what was done in this post

    var auth = new ApplicationOnlyAuthorizer
    {
        Credentials = new InMemoryCredentials
        {
            ConsumerKey = [ConsumerKey],
            ConsumerSecret = [ConsumerSecret]
        }
    };
    
    auth.Authorize();
    
    var _twitterContext = new TwitterContext(auth);
    
    var srch =
        (from search in _twitterContext.Search
         where search.Type == SearchType.Search &&
               search.Query == "twitter" &&
               search.Count == 7 &&
               search.GeoCode == "51.507351,-0.127758,1km"
         select search)
        .SingleOrDefault();
    
    Console.WriteLine("\nQuery: {0}\n", srch.SearchMetaData.Query);
    srch.Statuses.ForEach(entry =>
        Console.WriteLine(
            "ID: {0, -15}, Source: {1}\nContent: {2}\n",
            entry.StatusID, entry.Source, entry.Text));
    
    Console.ReadLine();