From f23dae307e06d95499b35dbdd8e341b45756b330 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Tue, 20 Sep 2022 23:11:52 +0530 Subject: First commit --- .../docs/mal2go/v4/anime/search-for-an-anime.md | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 content/docs/mal2go/v4/anime/search-for-an-anime.md (limited to 'content/docs/mal2go/v4/anime/search-for-an-anime.md') diff --git a/content/docs/mal2go/v4/anime/search-for-an-anime.md b/content/docs/mal2go/v4/anime/search-for-an-anime.md new file mode 100644 index 0000000..addf43a --- /dev/null +++ b/content/docs/mal2go/v4/anime/search-for-an-anime.md @@ -0,0 +1,50 @@ +--- +title: "Searching for an anime" +description: "Use a search string to get a list of animes" +weight: 2 +--- + +Use the `SearchAnime` method to search for an anime. This method takes these arguments: + +- `searchString string` Is pretty obvious. This term is used to search for an anime on MyAnimeList. +- `limit int` Is the max amount of search results to get. Max is 100. +- `offset int` Is the "offset" for the search results. If offset is greater than 0 the first n number of search reults will be ignored. +- `nsfw bool` Wether to include NSFW rated search results +- `fields []string` The fields to include in the response. [Here](/docs/mal2go/v4/anime/types#mal2goanimeanime) is a list of the valid fields. Just using an empty slice (`[]string{}`) will include all the fields. +The MyAnimeList API is picky about what fields to actually include with search results. To be sure that you are getting all the data it is recommended to use the [`GetAnimeById`](/docs/mal2go/v4/anime/get-anime-by-id) method which ensures that all the required fields are included. + + +Example: + +``` go +package main + +import ( + "github.com/MikunoNaka/MAL2Go/v4/anime" + "log" + "fmt" +) + +func main() { + authToken := "YOUR_TOKEN_HERE" + myClient := anime.Client { + AuthToken: "Bearer " + authToken, + } + + searchString := "mushishi" // search for mushishi + limit := 10 // get 10 search results + offset := 0 // no offset + searchNsfw := false // don't include NSFW results + fields := []string{"title"} // only pull the title + + searchResults, err := myClient.SearchAnime(searchString, limit, offset, searchNsfw, fields) + if err != nil { + log.Fatal(err) // remember kids, always handle errors + } + + // loop over the search results and print the title + for _, anime := range searchResults { + fmt.Println(anime.Title) + } +} +``` -- cgit v1.2.3