I'd like to get access to the public information about any user on Facebook. Basically, that means only user pictures and full names, that's all. It's the information you get when you open a page without being logged in, like this:
http://www.facebook.com/jurgenappelo
However, when I try to do this from code, Facebook returns this message:
"You are using an incompatible web browser."
I'm trying to mimic a Firefox browser, but that doesn't seem to work. Am I doing something wrong? Or is Facebook using other techniques to block this?
var requestString = "http://www.facebook.com/jurgenappelo";
var request = (HttpWebRequest)WebRequest.Create(requestString);
request.Headers.Add("HTTP_USER_AGENT", "Gecko/20050511 Firefox/1.0.4");
try
{
HttpWebResponse response =(HttpWebResponse)request.GetResponse();
if (response != null)
{
if (response.StatusCode == HttpStatusCode.OK)
{
Stream stream = response.GetResponseStream();
using (StreamReader reader = new StreamReader(stream))
{
var html = reader.ReadToEnd();
}
}
response.Close();
}
}
catch { }
Am I doing something wrong?
You are violating Facebook's terms and conditions:
You will not collect users' information, or otherwise access Facebook, using automated means (such as harvesting bots, robots, spiders, or scrapers) without our permission.
— http://www.facebook.com/terms.php?ref=pf
According to this:
Setting HTTP headers in .NET: This header must be modified using the appropriate property
you should try changing the:
request.Headers.Add("HTTP_USER_AGENT", "Gecko/20050511 Firefox/1.0.4");
to:
request.UserAgent = "Gecko/20050511 Firefox/1.0.4";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With