Add example
This commit is contained in:
parent
b1152a55cd
commit
43b274bbd2
42
example_test.go
Normal file
42
example_test.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package mastodon_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/mattn/go-mastodon"
|
||||
)
|
||||
|
||||
func ExampleApplication_RegisterApp() {
|
||||
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)
|
||||
}
|
||||
timeline, err := c.GetTimelineHome(context.Background())
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
for i := len(timeline) - 1; i >= 0; i-- {
|
||||
fmt.Println(timeline[i])
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user