import "github.com/mattn/go-mastodon"
Package mastodon provides functions and structs for accessing the mastodon API.
accounts.go apps.go compat.go helper.go instance.go lists.go mastodon.go notification.go polls.go report.go status.go streaming.go streaming_ws.go unixtime.go
const ( VisibilityPublic = "public" VisibilityUnlisted = "unlisted" VisibilityFollowersOnly = "private" VisibilityDirectMessage = "direct" )
Convenience constants for Toot.Visibility
Base64Encode returns the base64 data URI format string of the file.
Base64EncodeFileName returns the base64 data URI format string of the file with the file name.
String is a helper function to get the pointer value of a string.
type Account struct { ID ID `json:"id"` Username string `json:"username"` Acct string `json:"acct"` DisplayName string `json:"display_name"` Locked bool `json:"locked"` CreatedAt time.Time `json:"created_at"` FollowersCount int64 `json:"followers_count"` FollowingCount int64 `json:"following_count"` StatusesCount int64 `json:"statuses_count"` Note string `json:"note"` URL string `json:"url"` Avatar string `json:"avatar"` AvatarStatic string `json:"avatar_static"` Header string `json:"header"` HeaderStatic string `json:"header_static"` Emojis []Emoji `json:"emojis"` Moved *Account `json:"moved"` Fields []Field `json:"fields"` Bot bool `json:"bot"` }
Account hold information for mastodon account.
type AccountSource struct { Privacy *string `json:"privacy"` Sensitive *bool `json:"sensitive"` Language *string `json:"language"` Note *string `json:"note"` Fields *[]Field `json:"fields"` }
AccountSource is a Mastodon account profile field.
type AppConfig struct { http.Client Server string ClientName string // Where the user should be redirected after authorization (for no redirect, use urn:ietf:wg:oauth:2.0:oob) RedirectURIs string // This can be a space-separated list of items listed on the /settings/applications/new page of any Mastodon // instance. "read", "write", and "follow" are top-level scopes that include all the permissions of the more // specific scopes like "read:favourites", "write:statuses", and "write:follows". Scopes string // Optional. Website string }
AppConfig is a setting for registering applications.
type Application struct { ID ID `json:"id"` RedirectURI string `json:"redirect_uri"` ClientID string `json:"client_id"` ClientSecret string `json:"client_secret"` // AuthURI is not part of the Mastodon API; it is generated by go-mastodon. AuthURI string `json:"auth_uri,omitempty"` }
Application is mastodon application.
RegisterApp returns the mastodon application.
Code:
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)
type Attachment struct { ID ID `json:"id"` Type string `json:"type"` URL string `json:"url"` RemoteURL string `json:"remote_url"` PreviewURL string `json:"preview_url"` TextURL string `json:"text_url"` Description string `json:"description"` Meta AttachmentMeta `json:"meta"` }
Attachment hold information for attachment.
type AttachmentMeta struct { Original AttachmentSize `json:"original"` Small AttachmentSize `json:"small"` }
AttachmentMeta holds information for attachment metadata.
type AttachmentSize struct { Width int64 `json:"width"` Height int64 `json:"height"` Size string `json:"size"` Aspect float64 `json:"aspect"` }
AttachmentSize holds information for attatchment size.
type Card struct { URL string `json:"url"` Title string `json:"title"` Description string `json:"description"` Image string `json:"image"` Type string `json:"type"` AuthorName string `json:"author_name"` AuthorURL string `json:"author_url"` ProviderName string `json:"provider_name"` ProviderURL string `json:"provider_url"` HTML string `json:"html"` Width int64 `json:"width"` Height int64 `json:"height"` }
Card hold information for mastodon card.
Client is a API client for mastodon.
Code:
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]) }
NewClient return new mastodon API client.
AccountBlock block the account.
AccountFollow follow the account.
AccountMute mute the account.
AccountUnblock unblock the account.
AccountUnfollow unfollow the account.
AccountUnmute unmute the account.
AccountUpdate updates the information of the current user.
AccountsSearch search accounts by query.
func (c *Client) AddPushSubscription(ctx context.Context, endpoint string, public ecdsa.PublicKey, shared []byte, alerts PushAlerts) (*PushSubscription, error)
AddPushSubscription adds a new push subscription.
AddToList adds accounts to a list.
Only accounts already followed by the user can be added to a list.
Authenticate get access-token to the API.
AuthenticateToken logs in using a grant token returned by Application.AuthURI.
redirectURI should be the same as Application.RedirectURI.
ClearNotifications clear notifications.
CreateList creates a new list with a given title.
DeleteConversation delete the conversation specified by id.
DeleteList removes a list.
DeleteStatus delete the toot.
DismissNotification deletes a single notification.
Favourite is favourite the toot of id and return status of the favourite toot.
FollowRemoteUser send follow-request.
FollowRequestAuthorize is authorize the follow request of user with id.
FollowRequestReject is rejects the follow request of user with id.
GetAccount return Account.
GetAccountCurrentUser return Account of current user.
func (c *Client) GetAccountFollowers(ctx context.Context, id ID, pg *Pagination) ([]*Account, error)
GetAccountFollowers return followers list.
func (c *Client) GetAccountFollowing(ctx context.Context, id ID, pg *Pagination) ([]*Account, error)
GetAccountFollowing return following list.
GetAccountLists returns the lists containing a given account.
func (c *Client) GetAccountRelationships(ctx context.Context, ids []string) ([]*Relationship, error)
GetAccountRelationships return relationship for the account.
GetAccountStatuses return statuses by specified accuont.
GetBlocks return block list.
func (c *Client) GetConversations(ctx context.Context, pg *Pagination) ([]*Conversation, error)
GetConversations return direct conversations.
GetFavouritedBy returns the account list of the user who liked the toot of id.
GetFavourites return the favorite list of the current user.
GetFollowRequests return follow-requests.
GetInstance return Instance.
GetInstanceActivity return instance activity.
GetInstancePeers return instance peers.
GetList retrieves a list by ID.
GetListAccounts returns the accounts in a given list.
GetLists returns all the lists on the current account.
GetMutes returns the list of users muted by the current user.
GetNotification return notification.
func (c *Client) GetNotifications(ctx context.Context, pg *Pagination) ([]*Notification, error)
GetNotifications return notifications.
GetPushSubscription retrieves information about the active push subscription.
GetRebloggedBy returns the account list of the user who reblogged the toot of id.
GetReports return report of the current user.
GetStatus return status specified by id.
GetStatusCard return status specified by id.
GetStatusContext return status specified by id.
GetTimelineDirect return statuses from direct timeline.
func (c *Client) GetTimelineHashtag(ctx context.Context, tag string, isLocal bool, pg *Pagination) ([]*Status, error)
GetTimelineHashtag return statuses from tagged timeline.
GetTimelineHome return statuses from home timeline.
GetTimelineList return statuses from a list timeline.
func (c *Client) GetTimelineMedia(ctx context.Context, isLocal bool, pg *Pagination) ([]*Status, error)
GetTimelineMedia return statuses from media timeline. NOTE: This is an experimental feature of pawoo.net.
func (c *Client) GetTimelinePublic(ctx context.Context, isLocal bool, pg *Pagination) ([]*Status, error)
GetTimelinePublic return statuses from public timeline.
MarkConversationAsRead mark the conversation as read.
NewWSClient return WebSocket client.
PostStatus post the toot.
Reblog is reblog the toot of id and return status of reblog.
RemoveFromList removes accounts from a list.
RemovePushSubscription deletes the active push subscription.
RenameList assigns a new title to a list.
func (c *Client) Report(ctx context.Context, accountID ID, ids []ID, comment string) (*Report, error)
Report reports the report
Search search content with query.
func (c *Client) StreamingHashtag(ctx context.Context, tag string, isLocal bool) (chan Event, error)
StreamingHashtag return channel to read events on tagged timeline.
StreamingList return channel to read events on a list.
StreamingPublic return channel to read events on public.
StreamingUser return channel to read events on home.
Unfavourite is unfavourite the toot of id and return status of the unfavourite toot.
Unreblog is unreblog the toot of id and return status of the original toot.
func (c *Client) UpdatePushSubscription(ctx context.Context, alerts *PushAlerts) (*PushSubscription, error)
UpdatePushSubscription updates which type of notifications are sent for the active push subscription.
UploadMedia upload a media attachment from a file.
UploadMediaFromMedia uploads a media attachment from a Media struct.
UploadMediaFromReader uploads a media attachment from a io.Reader.
Config is a setting for access mastodon APIs.
type Context struct { Ancestors []*Status `json:"ancestors"` Descendants []*Status `json:"descendants"` }
Context hold information for mastodon context.
type Conversation struct { ID ID `json:"id"` Accounts []*Account `json:"accounts"` Unread bool `json:"unread"` LastStatus *Status `json:"last_status"` }
Conversation hold information for mastodon conversation.
DeleteEvent is struct for passing deletion event to app.
type Emoji struct { ShortCode string `json:"shortcode"` StaticURL string `json:"static_url"` URL string `json:"url"` VisibleInPicker bool `json:"visible_in_picker"` }
Emoji hold information for CustomEmoji.
type ErrorEvent struct {
// contains filtered or unexported fields
}
ErrorEvent is struct for passing errors to app.
func (e *ErrorEvent) Error() string
type Event interface {
// contains filtered or unexported methods
}
Event is interface passing events to app.
type Field struct { Name string `json:"name"` Value string `json:"value"` VerifiedAt time.Time `json:"verified_at"` }
Field is a Mastodon account profile field.
type History struct { Day string `json:"day"` Uses string `json:"uses"` Accounts string `json:"accounts"` }
History hold information for history.
type Instance struct { URI string `json:"uri"` Title string `json:"title"` Description string `json:"description"` EMail string `json:"email"` Version string `json:"version,omitempty"` Thumbnail string `json:"thumbnail,omitempty"` URLs map[string]string `json:"urls,omitempty"` Stats *InstanceStats `json:"stats,omitempty"` Languages []string `json:"languages"` ContactAccount *Account `json:"contact_account"` }
Instance hold information for mastodon instance.
type InstanceStats struct { UserCount int64 `json:"user_count"` StatusCount int64 `json:"status_count"` DomainCount int64 `json:"domain_count"` }
InstanceStats hold information for mastodon instance stats.
List is metadata for a list of users.
Media is struct to hold media.
type Mention struct { URL string `json:"url"` Username string `json:"username"` Acct string `json:"acct"` ID ID `json:"id"` }
Mention hold information for mention.
type Notification struct { ID ID `json:"id"` Type string `json:"type"` CreatedAt time.Time `json:"created_at"` Account Account `json:"account"` Status *Status `json:"status"` }
Notification hold information for mastodon notification.
type NotificationEvent struct { Notification *Notification `json:"notification"` }
NotificationEvent is struct for passing notification event to app.
Pagination is a struct for specifying the get range.
Code:
c := mastodon.NewClient(&mastodon.Config{ Server: "https://mstdn.jp", ClientID: "client-id", ClientSecret: "client-secret", }) var followers []*mastodon.Account var pg mastodon.Pagination for { fs, err := c.GetAccountFollowers(context.Background(), "1", &pg) if err != nil { log.Fatal(err) } followers = append(followers, fs...) if pg.MaxID == "" { break } time.Sleep(10 * time.Second) } for _, f := range followers { fmt.Println(f.Acct) }
type Poll struct { ID ID `json:"id"` ExpiresAt time.Time `json:"expires_at"` Expired bool `json:"expired"` Multiple bool `json:"multiple"` VotesCount int64 `json:"votes_count"` Options []PollOption `json:"options"` Voted bool `json:"voted"` }
Poll hold information for mastodon polls.
Poll hold information for a mastodon poll option.
type Profile struct { // If it is nil it will not be updated. // If it is empty, update it with empty. DisplayName *string Note *string Locked *bool Fields *[]Field Source *AccountSource // Set the base64 encoded character string of the image. Avatar string Header string }
Profile is a struct for updating profiles.
type PushAlerts struct { Follow *Sbool `json:"follow"` Favourite *Sbool `json:"favourite"` Reblog *Sbool `json:"reblog"` Mention *Sbool `json:"mention"` }
type PushSubscription struct { ID ID `json:"id"` Endpoint string `json:"endpoint"` ServerKey string `json:"server_key"` Alerts *PushAlerts `json:"alerts"` }
type Relationship struct { ID ID `json:"id"` Following bool `json:"following"` FollowedBy bool `json:"followed_by"` Blocking bool `json:"blocking"` Muting bool `json:"muting"` MutingNotifications bool `json:"muting_notifications"` Requested bool `json:"requested"` DomainBlocking bool `json:"domain_blocking"` ShowingReblogs bool `json:"showing_reblogs"` Endorsed bool `json:"endorsed"` }
Relationship hold information for relation-ship to the account.
Report hold information for mastodon report.
type Results struct { Accounts []*Account `json:"accounts"` Statuses []*Status `json:"statuses"` []*Tag `json:"hashtags"` }
Results hold information for search result.
type Status struct { ID ID `json:"id"` URI string `json:"uri"` URL string `json:"url"` Account Account `json:"account"` InReplyToID interface{} `json:"in_reply_to_id"` InReplyToAccountID interface{} `json:"in_reply_to_account_id"` Reblog *Status `json:"reblog"` Content string `json:"content"` CreatedAt time.Time `json:"created_at"` Emojis []Emoji `json:"emojis"` RepliesCount int64 `json:"replies_count"` ReblogsCount int64 `json:"reblogs_count"` FavouritesCount int64 `json:"favourites_count"` Reblogged interface{} `json:"reblogged"` Favourited interface{} `json:"favourited"` Muted interface{} `json:"muted"` Sensitive bool `json:"sensitive"` SpoilerText string `json:"spoiler_text"` Visibility string `json:"visibility"` MediaAttachments []Attachment `json:"media_attachments"` Mentions []Mention `json:"mentions"` Tags []Tag `json:"tags"` Card *Card `json:"card"` Poll *Poll `json:"poll"` Application Application `json:"application"` Language string `json:"language"` Pinned interface{} `json:"pinned"` }
Status is struct to hold status.
Stream is a struct of data that flows in streaming.
type Tag struct { Name string `json:"name"` URL string `json:"url"` History []History `json:"history"` }
Tag hold information for tag.
type Toot struct { Status string `json:"status"` InReplyToID ID `json:"in_reply_to_id"` MediaIDs []ID `json:"media_ids"` Sensitive bool `json:"sensitive"` SpoilerText string `json:"spoiler_text"` Visibility string `json:"visibility"` ScheduledAt *time.Time `json:"scheduled_at,omitempty"` }
Toot is struct to post status.
UpdateEvent is struct for passing status event to app.
WSClient is a WebSocket client.
func (c *WSClient) StreamingWSHashtag(ctx context.Context, tag string, isLocal bool) (chan Event, error)
StreamingWSHashtag return channel to read events on tagged timeline using WebSocket.
StreamingWSList return channel to read events on a list using WebSocket.
StreamingWSPublic return channel to read events on public using WebSocket.
StreamingWSUser return channel to read events on home using WebSocket.
type WeeklyActivity struct { Week Unixtime `json:"week"` Statuses int64 `json:"statuses,string"` Logins int64 `json:"logins,string"` Registrations int64 `json:"registrations,string"` }
WeeklyActivity hold information for mastodon weekly activity.
Path | Synopsis |
---|---|
cmd/mstdn |
Package mastodon imports 20 packages (graph) and is imported by 16 packages. Updated 2020-07-27. Refresh now. Tools for package owners.