Search code examples
c#.netfacebookfacebook-graph-apiscreen-scraping

Get user information on the Facebook profile page


I want to create a very basic C# application that can fetch publicly-available information for Facebook user profiles. I've read a few pages of Graph API but there is a problem. Here you can see a user profile that contains all sort of information for public:

http://tr-tr.facebook.com/people/A-Altan-Yurt/100002356385895

However I cannot get all of these information, using the Graph API with this link:

https://graph.facebook.com/100002356385895

I tried scraping the page but the returned document doesn't contain any useful information. Since all these info are public, I don't think there should be an access limit for them. What am I doing wrong here?


Solution

  • Yes, even public accessible data can not just be fetched outside of the facebook interface.

    In order to get the data you'll need a valid access token, for example if you try the url for the same user's feed you'll get:

    {
       "error": {
          "message": "An access token is required to request this resource.",
          "type": "OAuthException",
          "code": 104
       }
    }
    

    You can try this same url with the Graph API Explorer, and after you authorize this app, it will have an access token and you'll get the public feed of that user.

    The access token used there (in the API Explorer) is an app access token, which is probably the easiest token to get, here's the doc about Authenticating as an App. Once you get an access token you can start querying the graph api and get the public data.

    You can do it with other access token types, such as a user token.


    Edit

    Even when things are public for users on facebook, they are not public for applications and you will need to ask for the right permissions for let's say the education (user_education_history).

    You can see exactly which permission you need for each field in the documentation of the User object, in the fields table the 3rd column is titled Permissions and there you'll see what you need per field.