2017-04-27 05:03:24 +02:00
|
|
|
package mastodon_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
2017-05-13 21:40:19 +02:00
|
|
|
"time"
|
2017-04-27 05:03:24 +02:00
|
|
|
|
|
|
|
"github.com/mattn/go-mastodon"
|
|
|
|
)
|
|
|
|
|
2017-04-27 05:07:21 +02:00
|
|
|
func ExampleRegisterApp() {
|
2017-04-27 05:03:24 +02:00
|
|
|
app, err := mastodon.RegisterApp(context.Background(), &mastodon.AppConfig{
|
|
|
|
Server: "https://mstdn.jp",
|
|
|
|
ClientName: "client-name",
|
|
|
|
Scopes: "read write follow",
|
|
|
|
Website: "https://github.com/mattn/go-mastodon",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
fmt.Printf("client-id : %s\n", app.ClientID)
|
|
|
|
fmt.Printf("client-secret: %s\n", app.ClientSecret)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ExampleClient() {
|
|
|
|
c := mastodon.NewClient(&mastodon.Config{
|
|
|
|
Server: "https://mstdn.jp",
|
|
|
|
ClientID: "client-id",
|
|
|
|
ClientSecret: "client-secret",
|
|
|
|
})
|
|
|
|
err := c.Authenticate(context.Background(), "your-email", "your-password")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2017-05-06 16:03:19 +02:00
|
|
|
timeline, err := c.GetTimelineHome(context.Background(), nil)
|
2017-04-27 05:03:24 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
for i := len(timeline) - 1; i >= 0; i-- {
|
|
|
|
fmt.Println(timeline[i])
|
|
|
|
}
|
|
|
|
}
|
2017-05-13 21:40:19 +02:00
|
|
|
|
|
|
|
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 {
|
2017-10-23 03:09:08 +02:00
|
|
|
fs, err := c.GetAccountFollowers(context.Background(), "1", &pg)
|
2017-05-13 21:40:19 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|