-
Notifications
You must be signed in to change notification settings - Fork 57
04. Search
The Instagram.Searchbar
instance is the main access point for any search operations. It represents the searchbar in the app, where you can perform different types of searches. The default search will look for any resource matching the query, and is called "Top Search". The other available search methods are users, hashtags, and locations. Any search sequence is never just a single request. If you want to perform a search on the app, you first click on the discover page, causing discover posts to be loaded if they're not already. Then it will fetch your search history, and perform a search query on every letter you type into the search bar. After you found your desired search result, it will register that you clicked on it, and bring you to your desired resource.
This search behavior is mimicked by default, by making multiple search queries for every letter in your search query. It is possible to disable this and perform a quick search by passing in a single true
parameter into any of the search methods.
If you want to perform a regular top search, you can call one of:
// Perform a top search for the provided query
// return value is of type SearchResult
result, err := insta.Searchbar.Search("dogs")
// Exact same as above
result err := insta.Search("dogs")
// Perform quicksearch
result err := insta.Search("dogs", true)
The SearchResult
is always the return type of any search. It will contain the items searched for, as well as your search history (ooff), and some extra information, such as whether more results are available. If so, pagination is your friend. The search results are provided in one of 4 fields. Once you found your desired search result, you can let Instagram know by registering the click.
sb := insta.Searchbar
result, err := sb.Search("dogs")
// So called top items
items := result.Resuts
items[0].RegisterClick()
result, err := sb.SearchUser("The Primeagen")
items := result.Users
result.RegisterUserClick(items[0])
result, err := sb.SearchHashtag("photography")
items := result.Tags
result.RegisterHashtagClick(items[0])
result, err := sb.SearchLocation("Bali")
items := result.Places
result.RegisterLocationClick(items[0].Location)
If you want to search to visit a profile, it is best not to call a search method manually, but directly call insta.VisitProfile(user)
Disclaimer: This code is in no way affiliated with, authorized, maintained, sponsored, or endorsed by Instagram or any of its affiliates or subsidiaries. This is an independent and unofficial API. Use at your own risk. It is prohibited to use this API to spam users or the platform in any way.