Search

Search Facebook people, pages and posts with filters, and look up the cities, schools and companies to filter on with Unipile API.

The searches find what the account can see on Facebook. To search groups and events, see Facebook Groups and Facebook Events.

All three searches work the same way:

  • keywords is required, and can't be blank.
  • Send the same body with the cursor of the previous page to get the next one. An unknown cursor gives the first page.
  • Facebook sets the page size, usually 10 to 20 results, whatever the limit.
  • location, school and company are lists of IDs. Facebook takes one ID per filter: several get a 400.
  • Filters taking an ID need a numeric Facebook ID: another value gets a 400. An ID Facebook doesn't know, such as a deleted user, is ignored: the results come back without that filter.

Find the IDs of the filters

Cities, schools, companies and event categories are given by their ID. To find it from a name, use List Search Parameters:

typeFor the filter
locationlocation of the people, pages, posts and events searches.
schoolschool of the people search.
companycompany of the people search.
event_categorycategory of the events search. Without keywords, every category is returned.
curl --request GET \
     --url 'https://api.unipile.com/v2/{ACCOUNT_ID}/search/parameters?type=location&keywords=Lyon&limit=3' \
     --header 'X-API-KEY: {YOUR_API_KEY}'
{
  "data": [
    { "object": "SearchParameter", "id": "{CITY_ID}", "name": "Lyon, France", "picture_url": "https://..." }
  ]
}
  • Facebook suggests 10 cities, schools or companies at most: limit goes up to 10 for them. keywords is required, except for event_category.
  • Names are matched word by word: give the full name of a school or a company (HEC Paris rather than HEC).
  • Event categories are Facebook's fixed list (Music & Audio, Sports, Theater...), named in the account's language: keywords keeps those whose name contains it, such as music.
  • Facebook often has several pages for one school or company (campuses, duplicates). A filter only finds the people who chose that very page on their profile: if a value finds nobody, try another suggestion.

Search people

Use Perform People Search. Each result is a User of type individual: use its id with the Users, Messaging and Posts methods. Its description is the line shown under the name in the results, such as where the person lives, studies or works.

FieldValue
keywordsRequired. A name, or any words.
network_distance[1] for the account's friends, or [2] for the friends of its friends. Facebook filters one degree at a time: [3] or several degrees get a 400.
connections_ofOnly the friends of this user. Can't be combined with network_distance.
locationOnly the people living in this city: ["{CITY_ID}"].
schoolOnly the people who went to this school.
companyOnly the people who work or worked at this company.
curl --request POST \
     --url 'https://api.unipile.com/v2/{ACCOUNT_ID}/search/people' \
     --header 'X-API-KEY: {YOUR_API_KEY}' \
     --header 'content-type: application/json' \
     --data '{
  "keywords": "Marie",
  "network_distance": [2],
  "location": ["{CITY_ID}"]
}'
{
  "data": [
    {
      "object": "User",
      "id": "100012345678901",
      "type": "individual",
      "display_name": "Marie Martin",
      "public_identifier": "marie.martin",
      "profile_url": "https://www.facebook.com/marie.martin",
      "public_picture_url": "https://...",
      "description": "Works at Example · Lives in Lyon, France"
    }
  ],
  "next_cursor": "..."
}

Search pages

Use Perform Pages Search to find businesses, brands and public figures. Each result is a User of type organization; its description gives the page's category, address and audience.

FieldValue
keywordsRequired.
locationOnly the pages located in this city.

Search posts

Use Perform Posts Search. Results are posts, with the same fields as List all Posts: their comments and reactions are read with the Posts methods.

FieldValue
keywordsRequired.
sort_bymost_relevant (default) or most_recent.
seentrue for the posts the account has already seen (false gets a 400: there is no "not seen" filter).
start_date, end_dateDays (YYYY-MM-DD), both included, in the account's time zone. One of them is enough: without end_date the period ends today; without start_date, or before 2004, it starts in 2004.
posted_byOne option: { "me": true }, { "my_groups_and_pages": true }, { "public": true }, or one author: { "member": ["USER_ID"] }, { "company": ["{PAGE_ID}"] }, { "group": ["{GROUP_ID}"] }.
locationOnly the posts tagged in this city.
curl --request POST \
     --url 'https://api.unipile.com/v2/{ACCOUNT_ID}/search/posts' \
     --header 'X-API-KEY: {YOUR_API_KEY}' \
     --header 'content-type: application/json' \
     --data '{
  "keywords": "artificial intelligence",
  "start_date": "2024-03-01",
  "end_date": "2024-03-31",
  "posted_by": { "group": ["{GROUP_ID}"] }
}'

Errors

CauseAnswer
Missing or blank keywords, unknown field, wrong value, malformed date400 naming the field
network_distance other than [1] or [2], network_distance with connections_of, several posted_by options or IDs, false in posted_by or seen, end_date before start_date400
Several IDs in location, school or company400: "On Facebook, <field> takes one ID."
A filter ID that is not a numeric Facebook ID400: "<field> must be a numeric Facebook ID."
An account of another provider400: the provider does not support search methods

LinkedIn searches have their own routes: see Search LinkedIn users.


What’s Next

Continue with Facebook users.

Did this page help you?