aboutsummaryrefslogtreecommitdiff
path: root/content/docs/mal2go/v4/anime/get-anime-by-id.md
blob: ca310b3302eabec4cd985e410c3be4d4563361cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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."`