Searching with Graph API

Facebook allows developers to use simple Graph API calls, with search as the object, to make their queries in the Facebook database (I talk in much more detail about Graph API in Chapters 7 and 10).

Here is what a typical search query looks like:

https://graph.facebook.com/search?q=dummies

No matter what you're searching for, every search query you make using Graph API relies on some basic elements. The elements you need are as follows:

  • The main graph API URL: This is just https://graph.facebook.com, just like all Graph API calls.
  • search: This is your object. It is the path of your Graph API call, so the full URL would be https://graph.facebook.com/search.
  • A keyword or phrase to search for: This goes in your query parameters, and is specified via the q query parameter. If I want to search for “dummies books,” I would specify https://graph.facebook.com/search?q=dummies+books. This would search all public status updates on Facebook for “dummies books.” Go ahead; try it in your browser to see for yourself!
  • The type of objects among which you're trying to search: If you want to only search for people, or only search for Facebook Pages, you can specify an object type as a query parameter. This is done with the type query parameter. A type search query in Graph API would look like this:
    https://graph.facebook.com/search?q=dummies&type=page

Knowing what you can search for

Facebook allows you to search different types of objects, including the following: ...

Get Facebook® Application Development For Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.