diff options
Diffstat (limited to 'content/docs/mal2go/v4/anime/get-anime-by-id.md')
-rw-r--r-- | content/docs/mal2go/v4/anime/get-anime-by-id.md | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/content/docs/mal2go/v4/anime/get-anime-by-id.md b/content/docs/mal2go/v4/anime/get-anime-by-id.md new file mode 100644 index 0000000..ca310b3 --- /dev/null +++ b/content/docs/mal2go/v4/anime/get-anime-by-id.md @@ -0,0 +1,42 @@ +--- +title: "Getting an anime's information" +description: "Specify an anime's ID to get all the data about it." +weight: 3 +--- + +`GetAnimeById` takes in an anime's ID (which can be obtained using [`SearchAnime`](/docs/mal2go/v4/anime/search-for-an-anime) or through the URL of the anime's page on MAL) and returns information about it. This method takes these arguments: + +- `id int` The anime's ID +- `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. + +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, + } + + id := 457 + fields := []string{"title", "my_list_status", "num_episodes"} + + anime, err := myClient.GetAnimeById(id, fields) + if err != nil { + log.Fatal(err) // remember kids, always handle errors + } + + fmt.Printf("You have watched %d out of %d episodes in %s. Your list status for %s is %s.\n", anime.MyListStatus.EpWatched, anime.NumEpisodes, anime.Title, anime.Title, anime.MyListStatus.Status) +} +``` + +Above example prints something like +`"You have watched 26 out of 26 episodes in Mushishi. Your list status for Mushishi is completed."` |