Retreive Google+ count using C#
In my work with SeoTools I’m adding a Excel function for retreiving a page’s Google+ count (on request by @richardbaxterseo) and I found an excellent implementation in PHP.
In the spirit of sharing, here’s a port in C#:
private static Regex REGEX_GETURLCOUNT =
new Regex(@"<div[^>]+id=""aggregateCount""[^>]+>(\d*)</div>");
public static int GetUrlCount(string url)
{
string fetchUrl =
"https://plusone.google.com/u/0/_/+1/fastbutton?url="+
HttpUtility.UrlEncode(url)+"&count=true";
HttpWebRequest request =
(HttpWebRequest)WebRequest.Create(fetchUrl);
string response = new StreamReader(request.GetResponse()
.GetResponseStream()).ReadToEnd();
Match match = REGEX_GETURLCOUNT.Match(response);
if (match.Success)
{
return int.Parse(match.Groups[1].Value);
}
return 0;
}
And while I’m at it, here’s how to get the number of times an url has been tweeted:
private static Regex REGEX_GETURLCOUNT =
new Regex(@"(\d+) ");
public static int GetUrlCount(string url)
{
string fetchUrl = "http://api.tweetmeme.com/url_info?url=" +
HttpUtility.UrlEncode(url);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(fetchUrl);
string response = new StreamReader(request.GetResponse()
.GetResponseStream()).ReadToEnd();
Match match = REGEX_GETURLCOUNT.Match(response);
if (match.Success)
{
return int.Parse(match.Groups[1].Value);
}
return 0;
}
One Response to Retreive Google+ count using C#
Leave a Reply Cancel reply
SeoTools for Excel
FACEBOOK








Thanks for sharing. Good work!