facebookfacebook-graph-apisearch

How do I search Facebook for all users at a certain location using Graph-API


I have a project where I have to search Facebook for all people at a certain location and then apply further filters to the data. My problem and question is:

How do I get the initial data, using Graph API?

I know that it is possible, using the search field in Facebook itself. Just typing "All people living in ???" returns a list of people. I couldn't find such functionality in the Graph-API of Facebook. Here is what I tried:

I modified some parameters of the standard search request

and here is what I got:

{
  "error": {
    "message": "No node specified", 
    "type": "GraphMethodException", 
    "code": 100
  }
}

Using a similar query with location instead of center

and only got a confusing error that the location I wrote is wrong

{
  "error": {
    "message": "(#160) Invalid coordinates.  Coordinates must contain at least latitude and longitude.", 
    "type": "OAuthException", 
    "code": 160
  }
}

Then searching for a user with the coordinates as query parameter returned an empty result.

{"data": []}


Then I tried to search for a correct location to pass to the location parameter of the query

and I only got a deprecation error

{
  "error": {
    "message": "(#12) location search is deprecated for versions v2.0 and higher", 
    "type": "OAuthException", 
    "code": 12
  }
}

I don't know how to get to this. If someone could tell me, how to get this information, it would help me a lot, since I don't know what to try next.

I have found this question similar to my problem, but the accepted answer isn't really answering the question Facebook Search API - List all users based on location?


Solution

  • You can either search for a location OR search for a user, but you can definitely not search for "all users in an area". The Graph search on Facebook can handle a lot more things that you will never be able to get with the API. Think about privacy, i would not want any app to know if i am nearby, without even authorizing the App ;)

    Facebook docs: https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2#search

    For getting the locatoin where the user is living, you need to check out the user reference: https://developers.facebook.com/docs/graph-api/reference/v2.2/user

    There is a "location" field in there, you need to authorize a user with the "user_location" permission to get that information. It is not possible to get that information from any user. Just because you can see data on Facebook and it is public does not mean you can access it with an App, for privacy reasons this is only possible by authorizing the user.

    Scraping without an App is not allowed btw, check out the scraping terms: https://www.facebook.com/apps/site_scraping_tos_terms.php