From 073dfd699697be4b62329623e200d4f16c385dbd Mon Sep 17 00:00:00 2001 From: Maria Salcedo Date: Wed, 24 Apr 2024 19:51:40 +0200 Subject: [PATCH] Update README.md - Add a "post a Toot" example - Mark coding block as "go" --- README.md | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 455d22d..19cadf6 100644 --- a/README.md +++ b/README.md @@ -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 ( @@ -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) } ```