Home > Uncategorized > Find #Twitter #Influencers in your area, using #linqtotwitter

Find #Twitter #Influencers in your area, using #linqtotwitter


If you are promoting a product or service that is relevant only to a certain geographic area, i.e. a cafe or restaurant, then you might want to reach out to local twitter influencers – that is, people that carry alot of followers, and some might be amenable to tweet about your restaurant in return for a free meal.

Check out the demo at http://twitter.derrycreativescollective.com/

Or, if you’re a c# developer, and don’t need the use-case spelled out to you, then read on…

Here, I’ve used Linq2Twitter, which is FAR more stable than Tweetsharp, even though I do find the linq syntax a bit back-to-front.

It’s installed via Nuget as follows

Install-Package linqtotwitter

Now, What I’ve done, is created a web form page that returns JSON, which will be consumed by an ajax call. The call takes a strGeo parameter, which effectively is LAT,LON,RADIUS where radius, I’ve hard-coded to 10mi (10 miles)

You’ll need a Twitter developer account, and an App set up to get your authentication details, and you can’t use mine .. so they are excluded from the example below;

var auth = new SingleUserAuthorizer
CredentialStore = new SingleUserInMemoryCredentialStore
ConsumerKey = “…”,
ConsumerSecret = “…”,
OAuthToken = “….”,
OAuthTokenSecret = “…”
var twitterCtx = new TwitterContext(auth);
Search(twitterCtx, strGeo);

And the search method is as follows

void Search(TwitterContext twitterCtx, string geo)
var searchResponse =
(from search in twitterCtx.Search
where search.Type == SearchType.Search &&
search.Query == “a” &&
search.GeoCode == geo &&
search.Count == 100

select search)

if (searchResponse.Statuses.Count == 0)

if (searchResponse != null && searchResponse.Statuses != null)
var users = searchResponse.Statuses.Select(s =>
s.User).GroupBy(u =>
u.ScreenNameResponse).Select(g =>
g.FirstOrDefault()).OrderByDescending(u =>
var jsSerializer = new JavaScriptSerializer();
var strJson = jsSerializer.Serialize(users);
Response.AppendHeader(“Access-Control-Allow-Origin”, “*”);
Response.Headers.Add(“Content-type”, “text/json”);

This, searches a given geographic area for tweets, and grabs 100 of them. It then takes all the users that posted the tweets, removes duplicates, and orders by follower count. It then spits the lot out as JSON, with a CORS header added.

On the web side, I use Google to reverse geocode the city typed by the user, to get a lat / lon, using the following code

var address = $(“#tbLocation”).val();
geocoder.geocode({ ‘address’: address }, function (results, status) {
if (status === ‘OK’) {
var geoResult = results[0].geometry.location;
var strGeo = geoResult.lat() + “,” + geoResult.lng() + “,10mi”;
} else {
alert(‘Geocode was not successful for the following reason: ‘ + status);

And, then I have defined callAPI as follows;

function callAPI(geo) {
console.log(“searching: ” + geo);
$.getJSON(“/PopularAjax.aspx?geo=” + geo,
function (data) {
var tpl = $(“#tplItem”).html();
var strHtml = Mustache.render(tpl, data);

Where I take the raw JSON returned by the AJAX and render it against a Mustache template, which is then injected into a Bootrap-based page.

Quite simple, but hopefully, it is useful to someone.


Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: