Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ See [examples/session_login.py](examples/session_login.py) for a standalone scri

### Search locations by name or exact pk

The name lookup below uses the legacy web search route and can raise `ClientNotFoundError` on HTTP 404. Use `fbsearch_places()` for mobile place search.

```python
from instagrapi import Client

Expand Down
4 changes: 3 additions & 1 deletion docs/usage-guide/location.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ positive external ID and a nonempty source. This also avoids legacy name search
when `location_build()` or `location_complete()` resolves that PK. Missing
coordinates in private info stay `None`. Incomplete private
identity still uses the existing name-search fallback. `location_search_name()`
continues to use legacy `top_search`.
calls legacy `top_search()` and can raise `ClientNotFoundError` on HTTP 404.
The same error can propagate when `location_search_pk()` falls back to
name search. Use `fbsearch_places()` for mobile place search.

Example:

Expand Down
22 changes: 18 additions & 4 deletions docs/usage-guide/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,25 @@ If `media_search()` fails with `Missing media_grid in fbsearch/top_serp response
| `search_users(query: str)` | `List[UserShort]` | User search via `users/search/`. |
| `search_hashtags(query: str)` | `List[Hashtag]` | Hashtag search via `tags/search/`. |
| `search_music(query: str)` | `List[Track]` | Music/audio search via `music/audio_global_search/`. |
| `fbsearch_topsearch_flat(query: str)` | `List[dict]` | Legacy flat top-search via `fbsearch/topsearch_flat/`. |
| `fbsearch_topsearch_flat(query: str)` | `List[dict]` | Blended mobile search via `fbsearch/topsearch_flat/`. Returns flat entries such as `user` and `hashtag`. |
| `web_search_users(query: str)` | `List[UserShort]` | Accounts from the web search box through GraphQL with an authenticated session. |
| `web_search_topsearch(query: str)` | `dict` | Raw web top-search payload via `web/search/topsearch/`. |
| `web_search_topsearch_hashtags(query: str)` | `List[Hashtag]` | Extract hashtags from the web top-search payload. |
| `web_search_topsearch(query: str)` | `dict` | Legacy mixed search via `i.instagram.com/api/v1/web/search/topsearch/`. The route can return HTTP 404. |
| `web_search_topsearch_hashtags(query: str)` | `List[Hashtag]` | Extract hashtags through `web_search_topsearch()`. Uses the same legacy route. |
| `fbsearch_suggested_profiles(user_id: str)` | `List[UserShort]` | Suggested profiles via `fbsearch/accounts_recs/`. |
| `fbsearch_recent()` | `List[Tuple[int, ...]]` | Recently searched items. |

For places, see [Location](location.md).
### When legacy web search returns HTTP 404

The legacy `web_search_topsearch()` route returned HTTP 404 on an authenticated session. The anonymous `top_search()` route on `www.instagram.com` also returned HTTP 404. See [instagrapi #2994](https://github.com/subzeroid/instagrapi/issues/2994) for the observed responses.

Use `fbsearch_topsearch_flat()` to retrieve accounts and hashtags together. It returns a list of raw entries, so extract each result type from the entries.

```python
entries = cl.fbsearch_topsearch_flat("python")
accounts = [entry["user"] for entry in entries if "user" in entry]
hashtags = [entry["hashtag"] for entry in entries if "hashtag" in entry]
```

For typed web account results, use `web_search_users()`. Its return value contains only the accounts from the GraphQL search response. The web response returned hashtags for a hashtag query in live testing. For typed hashtag results, use `search_hashtags()` through the mobile API.

The tested place-name query returned an empty `places` list. For mobile place search, use `fbsearch_places()`. See the [Location guide](location.md) for details.
Loading