Tuesday, March 20, 2012

How to use the Graph API to search for places

Facebook has recently updated their documentation on their search* feature. This is exciting news! In this blog I want to show you how simple it is to search for places or locations in a geographical area. All you need to know is the center coordinates of the location to be searched.

* note: Facebook's made it hard to directly link to the information as they have no anchor tag in the long page. Scroll down to the "Search" heading.

To search for places near a geographical location


https://graph.facebook.com/search?q=coffee&type=place&center=37.76,-122.427&distance=1000&access_token=VALID_ACCESS_TOKEN

I believe the distance parameter is in meters, but it is hard to tell because they've left that part undocumented.

To search for objects near a geographical location


https://graph.facebook.com/search?type=location&center=37.76,-122.427&distance=1000&access_token=VALID_ACCESS_TOKEN

What's interesting is you will get check-ins from friends if you're using a user access token for this query. Here's what Facebook says:

In addition, the returned objects will be those in which you or your friend have been tagged, or those objects that were created by you or your friends. There are important behavioral differences in the results depending on the permissions your app has acquired. Please see the documentation for the location_post FQL table for more information.

Happy coding! And as always be nice to your API.


No comments:

Post a Comment