Skip to content

Instantly share code, notes, and snippets.

@uraimo
Created November 7, 2022 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uraimo/174ffaa816d894b5ab9fda89d085139b to your computer and use it in GitHub Desktop.
Save uraimo/174ffaa816d894b5ab9fda89d085139b to your computer and use it in GitHub Desktop.
Post a new toot to a Mastodon instance in Go
package main
import (
"os"
"strings"
"context"
"log"
"github.com/mattn/go-mastodon" //Thanks Mattn!
)
func main() {
args := os.Args[1:]
toot := strings.Join(args," ")
c := mastodon.NewClient(&mastodon.Config{
Server: "https://mastodon.social",
ClientID: "133t133t133t133t133t133t133t133t133t133t133t",
ClientSecret: "133t133t133t133t133t133t133t133t-133t133t",
})
err := c.Authenticate(context.Background(), "youremail", "yourpwd")
if err != nil {
log.Fatal(err)
}
_, err = c.PostStatus(context.Background(), &mastodon.Toot{
Status: toot,
})
if err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment