views:

393

answers:

2

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 { }
+7  A: 
David Dorward
Do you have to agree with the facebook terms if you are not a member?
HerdplattenToni
From the top of that URL: "This Statement of Rights and Responsibilities ("Statement") derives from the Facebook Principles, and governs our relationship with users and others who interact with Facebook. By using or accessing Facebook, you agree to this Statement."
David Dorward
This may or may not be enforceable (IANAL), but even if it isn't, disobeying is disrespecting Facebook's wishes, and it is their servers you are accessing.
David Dorward
Thanks for your input.I've seen other services (like http://www.pipl.com) doing exactly the same (only fetching full name and picture), and they're not being secretive about it either.If Facebook had a problem with that I assume they would have sued Pipl.com already. Wouldn't they?
Noop
I repeat: IANAL. I'd look for an official API to get this information rather than trying to screen scrape.
David Dorward
Thanks again, I understand your response. We already tried the official API, and it is of no use in this case.As a developer I just want to know how to get stuff working. Let's leave the lawyer-stuff to the lawyers. That's their job, not mine. If I asked a question on how to record radio stations the answer "You shouldn't do that" would also not be really useful.
Noop
+1  A: 

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";
Thanks, this solved the problem!
Noop

related questions