Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I fetch full name and picture from any user's Facebook page?

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 { }
like image 694
Jurgen Appelo Avatar asked Dec 23 '22 10:12

Jurgen Appelo


2 Answers

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

like image 97
Quentin Avatar answered May 16 '23 06:05

Quentin


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";
like image 34
user142360 Avatar answered May 16 '23 06:05

user142360