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:
keywordsis required, and can't be blank.- Send the same body with the
cursorof the previous page to get the next one. An unknowncursorgives the first page. - Facebook sets the page size, usually 10 to 20 results, whatever the
limit. location,schoolandcompanyare lists of IDs. Facebook takes one ID per filter: several get a400.- 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:
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:
limitgoes up to 10 for them.keywordsis required, except forevent_category. - Names are matched word by word: give the full name of a school or a company (
HEC Parisrather thanHEC). - Event categories are Facebook's fixed list (Music & Audio, Sports, Theater...), named in the account's language:
keywordskeeps those whose name contains it, such asmusic. - 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.
| Field | Value |
|---|---|
keywords | Required. 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_of | Only the friends of this user. Can't be combined with network_distance. |
location | Only the people living in this city: ["{CITY_ID}"]. |
school | Only the people who went to this school. |
company | Only 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.
| Field | Value |
|---|---|
keywords | Required. |
location | Only 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.
| Field | Value |
|---|---|
keywords | Required. |
sort_by | most_relevant (default) or most_recent. |
seen | true for the posts the account has already seen (false gets a 400: there is no "not seen" filter). |
start_date, end_date | Days (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_by | One option: { "me": true }, { "my_groups_and_pages": true }, { "public": true }, or one author: { "member": ["USER_ID"] }, { "company": ["{PAGE_ID}"] }, { "group": ["{GROUP_ID}"] }. |
location | Only 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
| Cause | Answer |
|---|---|
Missing or blank keywords, unknown field, wrong value, malformed date | 400 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_date | 400 |
Several IDs in location, school or company | 400: "On Facebook, <field> takes one ID." |
| A filter ID that is not a numeric Facebook ID | 400: "<field> must be a numeric Facebook ID." |
| An account of another provider | 400: the provider does not support search methods |
LinkedIn searches have their own routes: see Search LinkedIn users.
Updated 4 days ago
What’s Next
Continue with Facebook users.