Merge pull request #58 from 178inaba/example_pagination

Add ExamplePagination
This commit is contained in:
mattn 2017-05-14 15:26:08 +09:00 committed by GitHub
commit 266fe36074

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"log" "log"
"time"
"github.com/mattn/go-mastodon" "github.com/mattn/go-mastodon"
) )
@ -40,3 +41,27 @@ func ExampleClient() {
fmt.Println(timeline[i]) fmt.Println(timeline[i])
} }
} }
func ExamplePagination() {
c := mastodon.NewClient(&mastodon.Config{
Server: "https://mstdn.jp",
ClientID: "client-id",
ClientSecret: "client-secret",
})
var followers []*mastodon.Account
var pg mastodon.Pagination
for {
fs, err := c.GetAccountFollowers(context.Background(), 1, &pg)
if err != nil {
log.Fatal(err)
}
followers = append(followers, fs...)
if pg.MaxID == 0 {
break
}
time.Sleep(10 * time.Second)
}
for _, f := range followers {
fmt.Println(f.Acct)
}
}