mastodon client for golang
 
 
Go to file
Paul Waldo 5aff7298c3
Merge pull request #2 from PaulWaldo/develop
2023-05-02 08:06:45 -04:00
.github Chore: update actions and go versions 2022-12-28 23:55:58 +09:00
.vscode Adds GetFollowedTags 2023-03-12 09:25:45 -04:00
cmd/mstdn Adds GetFollowedTags 2023-03-12 09:25:45 -04:00
testdata add missing file 2017-04-17 14:03:40 +09:00
.gitignore add .gitignore 2017-04-14 23:47:04 +09:00
LICENSE add LICENSE 2017-04-27 09:20:14 +09:00
README.md Adds documentation for followed_tags and AuthenticateToken workflow 2023-05-02 08:01:23 -04:00
accounts.go Adds GetFollowedTags 2023-03-12 09:25:45 -04:00
accounts_test.go Adds GetFollowedTags 2023-03-12 09:25:45 -04:00
apps.go minor spelling fixes 2022-11-14 09:04:46 +09:00
apps_test.go remove redundent return statements 2022-11-16 10:49:14 +09:00
compat.go Add support for /api/v1/push/subscription 2019-09-30 17:19:22 +09:00
example_test.go also convert to string in attachments, pagenation 2017-10-25 10:22:39 +09:00
filters.go add support for filters 2022-05-01 22:52:28 +09:00
filters_test.go add support for filters 2022-05-01 22:52:28 +09:00
go.mod Separate go.mod 2022-06-04 23:01:37 +09:00
go.sum Separate go.mod 2022-06-04 23:01:37 +09:00
go.test.sh Temporary disable test with -race 2019-06-22 02:17:37 +09:00
go.work Adds GetFollowedTags 2023-03-12 09:25:45 -04:00
helper.go Fix to parse API error 2017-04-19 14:32:53 +09:00
helper_test.go Fix ineffectual assignments 2019-09-30 17:14:20 +09:00
instance.go Update: support configuration 2022-12-28 23:51:48 +09:00
instance_test.go Update: support configuration 2022-12-28 23:51:48 +09:00
lists.go Add list API support. 2019-05-12 23:58:10 +09:00
lists_test.go Remove unused variables 2022-11-17 07:15:36 +09:00
mastodon.go add support for language 2022-11-17 07:16:38 +09:00
mastodon_test.go Add support for edited statuses 2022-12-28 23:59:18 +09:00
notification.go minor spelling fixes 2022-11-14 09:04:46 +09:00
notification_test.go remove redundent return statements 2022-11-16 10:49:14 +09:00
polls.go minor spelling fixes 2022-11-14 09:04:46 +09:00
polls_test.go Add support to vote on polls. Add more fields to Poll 2021-11-05 00:02:01 +09:00
report.go minor spelling fixes 2022-11-14 09:04:46 +09:00
report_test.go Remove unused variables 2022-11-17 07:15:36 +09:00
status.go add comment for GetStatusSource 2022-11-30 08:16:07 +09:00
status_test.go add source, history for statuses and option to update a status 2022-11-30 08:16:07 +09:00
streaming.go Add support for edited statuses 2022-12-28 23:59:18 +09:00
streaming_test.go Add support for edited statuses 2022-12-28 23:59:18 +09:00
streaming_ws.go Add support for edited statuses 2022-12-28 23:59:18 +09:00
streaming_ws_test.go Add support for edited statuses 2022-12-28 23:59:18 +09:00
unixtime.go Add GetInstanceActivity and GetInstancePeers 2018-01-29 12:33:17 +09:00

README.md

go-mastodon

Build Status Codecov Go Reference Go Report Card

Usage

Application

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/mattn/go-mastodon"
)

func main() {
	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)
}

Client

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/mattn/go-mastodon"
)

func main() {
	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(), nil)
	if err != nil {
		log.Fatal(err)
	}
	for i := len(timeline) - 1; i >= 0; i-- {
		fmt.Println(timeline[i])
	}
}

Client with Token

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.

package main

import (
	"context"
	"fmt"
	"log"
	"net/url"

	"github.com/mattn/go-mastodon"
)

func main() {
	appConfig := &mastodon.AppConfig{
		Server:       "https://stranger.social",
		ClientName:   "client-name",
		Scopes:       "read write follow",
		Website:      "https://github.com/mattn/go-mastodon",
		RedirectURIs: "urn:ietf:wg:oauth:2.0:oob",
	}
	app, err := mastodon.RegisterApp(context.Background(), appConfig)
	if err != nil {
		log.Fatal(err)
	}

	// Have the user manually get the token and send it back to us
	u, err := url.Parse(app.AuthURI)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Open your browser to \n%s\n and copy/paste the given token\n", u)
	var token string
	fmt.Print("Paste the token here:")
	fmt.Scanln(&token)
	config := &mastodon.Config{
		Server:       "https://stranger.social",
		ClientID:     app.ClientID,
		ClientSecret: app.ClientSecret,
		AccessToken:  token,
	}

	c := mastodon.NewClient(config)
	err = c.AuthenticateToken(context.Background(), token, "urn:ietf:wg:oauth:2.0:oob")
	if err != nil {
        log.Fatal((err)
	}

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

Status of implementations

  • GET /api/v1/accounts/:id
  • GET /api/v1/accounts/verify_credentials
  • PATCH /api/v1/accounts/update_credentials
  • GET /api/v1/accounts/:id/followers
  • GET /api/v1/accounts/:id/following
  • GET /api/v1/accounts/:id/statuses
  • POST /api/v1/accounts/:id/follow
  • POST /api/v1/accounts/:id/unfollow
  • GET /api/v1/accounts/:id/block
  • GET /api/v1/accounts/:id/unblock
  • GET /api/v1/accounts/:id/mute
  • GET /api/v1/accounts/:id/unmute
  • GET /api/v1/accounts/:id/lists
  • GET /api/v1/accounts/relationships
  • GET /api/v1/accounts/search
  • GET /api/v1/apps/verify_credentials
  • GET /api/v1/bookmarks
  • POST /api/v1/apps
  • GET /api/v1/blocks
  • GET /api/v1/conversations
  • DELETE /api/v1/conversations/:id
  • POST /api/v1/conversations/:id/read
  • GET /api/v1/favourites
  • GET /api/v1/filters
  • POST /api/v1/filters
  • GET /api/v1/filters/:id
  • PUT /api/v1/filters/:id
  • DELETE /api/v1/filters/:id
  • GET /api/v1/follow_requests
  • POST /api/v1/follow_requests/:id/authorize
  • POST /api/v1/follow_requests/:id/reject
  • GET /api/v1/followed_tags
  • POST /api/v1/follows
  • GET /api/v1/instance
  • GET /api/v1/instance/activity
  • GET /api/v1/instance/peers
  • GET /api/v1/lists
  • GET /api/v1/lists/:id/accounts
  • GET /api/v1/lists/:id
  • POST /api/v1/lists
  • PUT /api/v1/lists/:id
  • DELETE /api/v1/lists/:id
  • POST /api/v1/lists/:id/accounts
  • DELETE /api/v1/lists/:id/accounts
  • POST /api/v1/media
  • GET /api/v1/mutes
  • GET /api/v1/notifications
  • GET /api/v1/notifications/:id
  • POST /api/v1/notifications/:id/dismiss
  • POST /api/v1/notifications/clear
  • POST /api/v1/push/subscription
  • GET /api/v1/push/subscription
  • PUT /api/v1/push/subscription
  • DELETE /api/v1/push/subscription
  • GET /api/v1/reports
  • POST /api/v1/reports
  • GET /api/v2/search
  • GET /api/v1/statuses/:id
  • GET /api/v1/statuses/:id/context
  • GET /api/v1/statuses/:id/card
  • GET /api/v1/statuses/:id/history
  • GET /api/v1/statuses/:id/reblogged_by
  • GET /api/v1/statuses/:id/source
  • GET /api/v1/statuses/:id/favourited_by
  • POST /api/v1/statuses
  • PUT /api/v1/statuses/:id
  • DELETE /api/v1/statuses/:id
  • POST /api/v1/statuses/:id/reblog
  • POST /api/v1/statuses/:id/unreblog
  • POST /api/v1/statuses/:id/favourite
  • POST /api/v1/statuses/:id/unfavourite
  • POST /api/v1/statuses/:id/bookmark
  • POST /api/v1/statuses/:id/unbookmark
  • GET /api/v1/timelines/home
  • GET /api/v1/timelines/public
  • GET /api/v1/timelines/tag/:hashtag
  • GET /api/v1/timelines/list/:id
  • GET /api/v1/streaming/user
  • GET /api/v1/streaming/public
  • GET /api/v1/streaming/hashtag?tag=:hashtag
  • GET /api/v1/streaming/hashtag/local?tag=:hashtag
  • GET /api/v1/streaming/list?list=:list_id
  • GET /api/v1/streaming/direct

Installation

go install github.com/mattn/go-mastodon@latest

License

MIT

Author

Yasuhiro Matsumoto (a.k.a. mattn)