aboutsummaryrefslogtreecommitdiff
path: root/content/docs/mal2go/v4/user/anime/get-anime-list.md
blob: 22f6f4a6c401196a67ea05a153295cfe8e095490 (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
43
44
45
46
47
48
49
50
51
52
53
---
title: "Get anime list"
description: "Get an arbitrary user's animelist"
weight: 2
---

Use the `GetAnimeList` method to get the animelist of a user.
This method takes these arguments:

- `username string` Username of the user to get animelist of. An empty string or `"@me"` will return the logged-in user's list
- `status string` Status of the animes, accepted values are `watching`, `completed`, `on_hold`, `dropped` and `plan_to_watch`
- `sort string` How to sort the list, accepted values are `list_score`, `list_updated_at`, `anime_title`, `anime_start_date` and `anime_id`
- `limit int` Limit of results to pull, Max is 1000
- `offset int` Offset for the results
- `nsfw bool` To include NSFW elements or not
- `fields []string` Specify which fields to get for each anime. [List of valid fields](/docs/mal2go/v4/anime/types/#mal2goanimeanime)

Example: 

``` go
package main

import (
  "github.com/MikunoNaka/MAL2Go/v4/user/anime"
  "log"
  "fmt"
)

func main() {
  authToken := "YOUR_TOKEN_HERE"
  myClient := anime.Client {
    AuthToken: "Bearer " + authToken,
  }
  
  animeList, nextPageExists, err := myClient.GetAnimeList("0ZeroTsu", "completed", "list_score", 1000, 0, true, []string{"title"})
  if err != nil {
    log.Fatal(err)
  }
  
  for _, i := range animeList {
    fmt.Println(i.Title)
  }
  
  if nextPageExists {
    fmt.Println("This user has even more animes in their animelist.")
    fmt.Println("Please increase the offset to look at the hidden entries.")
  }
}
```

The above example prints the first 1000 entries from 0ZeroTsu's (mine) completed anime list. 
If the list has more than 1000 items, the `nextPageExists` becomes true, which can be used to show
a notice like this, or maybe append the remaining items to animeList by calling `anime.GetAnimeList` with a higher offset.