Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
- Add a "post a Toot" example
- Mark coding block as "go"
  • Loading branch information
mariasalcedo authored and mattn committed May 4, 2024
1 parent d53cfea commit 073dfd6
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func main() {
This option lets the user avoid storing login credentials in the application. Instead, the user's Mastodon server
provides an access token which is used to authenticate. This token can be stored in the application, but should be guarded.

```
```go
package main

import (
Expand Down Expand Up @@ -117,14 +117,30 @@ func main() {
c := mastodon.NewClient(config)
err = c.AuthenticateToken(context.Background(), token, "urn:ietf:wg:oauth:2.0:oob")
if err != nil {
log.Fatal((err)
log.Fatal(err)
}

acct, err := c.GetAccountCurrentUser(context.Background())
if err != nil {
log.Fatal((err)
log.Fatal(err)
}
fmt.Printf("Account is %v\n", acct)

finalText := "This is the content of my new post!"
visibility := "public"

// Post a toot
toot := mastodon.Toot{
Status: finalText,
Visibility: visibility,
}
post, err := c.PostStatus(context.Background(), &toot)

if err != nil {
log.Fatalf("%#v\n", err)
}

fmt.Printf("My new post is %v\n", post)
}
```

Expand Down

0 comments on commit 073dfd6

Please sign in to comment.