Documentation
¶
Index ¶
- Constants
- Variables
- func BlockUser(client Client, sourceUserID, targetUserID string, opts RequestOptions) (json.RawMessage, error)
- func Bookmark(client Client, userID, postID string, opts RequestOptions) (json.RawMessage, error)
- func CreatePost(client Client, text string, mediaIDs []string, opts RequestOptions) (json.RawMessage, error)
- func DeletePost(client Client, postID string, opts RequestOptions) (json.RawMessage, error)
- func ExecuteMediaStatus(mediaID, authType, username string, verbose, wait, trace bool, ...) error
- func ExecuteMediaUpload(filePath, mediaType, mediaCategory, authType, username string, ...) error
- func ExecuteRequest(options RequestOptions, client Client) error
- func ExecuteStreamRequest(options RequestOptions, client Client) error
- func ExtractCommand(url string) string
- func ExtractMediaID(url string) string
- func ExtractSegmentIndex(data string) string
- func FollowUser(client Client, sourceUserID, targetUserID string, opts RequestOptions) (json.RawMessage, error)
- func GetBookmarks(client Client, userID string, maxResults int, opts RequestOptions) (json.RawMessage, error)
- func GetDMEvents(client Client, maxResults int, opts RequestOptions) (json.RawMessage, error)
- func GetFollowers(client Client, userID string, maxResults int, opts RequestOptions) (json.RawMessage, error)
- func GetFollowing(client Client, userID string, maxResults int, opts RequestOptions) (json.RawMessage, error)
- func GetLikedPosts(client Client, userID string, maxResults int, opts RequestOptions) (json.RawMessage, error)
- func GetMe(client Client, opts RequestOptions) (json.RawMessage, error)
- func GetMentions(client Client, userID string, maxResults int, opts RequestOptions) (json.RawMessage, error)
- func GetTimeline(client Client, userID string, maxResults int, opts RequestOptions) (json.RawMessage, error)
- func GetUserPosts(client Client, userID string, maxResults int, opts RequestOptions) (json.RawMessage, error)
- func HandleMediaAppendRequest(options RequestOptions, mediaFile string, client Client) (json.RawMessage, error)
- func HandleRequest(options RequestOptions, forceStream bool, mediaFile string, client Client) error
- func IsMediaAppendRequest(url string, mediaFile string) bool
- func IsStreamingEndpoint(endpoint string) bool
- func LikePost(client Client, userID, postID string, opts RequestOptions) (json.RawMessage, error)
- func LookupUser(client Client, username string, opts RequestOptions) (json.RawMessage, error)
- func MuteUser(client Client, sourceUserID, targetUserID string, opts RequestOptions) (json.RawMessage, error)
- func QuotePost(client Client, postID, text string, opts RequestOptions) (json.RawMessage, error)
- func ReadPost(client Client, postID string, opts RequestOptions) (json.RawMessage, error)
- func ReplyToPost(client Client, postID, text string, mediaIDs []string, opts RequestOptions) (json.RawMessage, error)
- func Repost(client Client, userID, postID string, opts RequestOptions) (json.RawMessage, error)
- func ResolvePostID(input string) string
- func ResolveUsername(input string) string
- func SearchPosts(client Client, query string, maxResults int, opts RequestOptions) (json.RawMessage, error)
- func SendDM(client Client, participantID, text string, opts RequestOptions) (json.RawMessage, error)
- func UnblockUser(client Client, sourceUserID, targetUserID string, opts RequestOptions) (json.RawMessage, error)
- func Unbookmark(client Client, userID, postID string, opts RequestOptions) (json.RawMessage, error)
- func UnfollowUser(client Client, sourceUserID, targetUserID string, opts RequestOptions) (json.RawMessage, error)
- func UnlikePost(client Client, userID, postID string, opts RequestOptions) (json.RawMessage, error)
- func UnmuteUser(client Client, sourceUserID, targetUserID string, opts RequestOptions) (json.RawMessage, error)
- func Unrepost(client Client, userID, postID string, opts RequestOptions) (json.RawMessage, error)
- type ApiClient
- func (c *ApiClient) BuildMultipartRequest(options MultipartOptions) (*http.Request, error)
- func (c *ApiClient) BuildRequest(requestOptions RequestOptions) (*http.Request, error)
- func (c *ApiClient) SendMultipartRequest(options MultipartOptions) (json.RawMessage, error)
- func (c *ApiClient) SendRequest(options RequestOptions) (json.RawMessage, error)
- func (c *ApiClient) StreamRequest(options RequestOptions) error
- type Client
- type InitRequest
- type MediaUploader
- func (m *MediaUploader) Append() error
- func (m *MediaUploader) CheckStatus() (json.RawMessage, error)
- func (m *MediaUploader) Finalize() (json.RawMessage, error)
- func (m *MediaUploader) GetMediaID() string
- func (m *MediaUploader) Init(mediaType string, mediaCategory string) error
- func (m *MediaUploader) SetMediaID(mediaID string)
- func (m *MediaUploader) WaitForProcessing() (json.RawMessage, error)
- type MultipartOptions
- type PostBody
- type PostMedia
- type PostPoll
- type PostReply
- type RequestOptions
Constants ¶
const (
// MediaEndpoint is the endpoint for media uploads
MediaEndpoint = "/2/media/upload"
)
Variables ¶
var StreamingEndpoints = map[string]bool{ "/2/tweets/search/stream": true, "/2/tweets/sample/stream": true, "/2/tweets/sample10/stream": true, "/2/tweets/firehose/stream": true, "/2/tweets/firehose/stream/lang/en": true, "/2/tweets/firehose/stream/lang/ja": true, "/2/tweets/firehose/stream/lang/ko": true, "/2/tweets/firehose/stream/lang/pt": true, }
StreamingEndpoints is a map of endpoint prefixes that should be streamed
Functions ¶
func BlockUser ¶
func BlockUser(client Client, sourceUserID, targetUserID string, opts RequestOptions) (json.RawMessage, error)
BlockUser blocks a user.
func Bookmark ¶
func Bookmark(client Client, userID, postID string, opts RequestOptions) (json.RawMessage, error)
Bookmark bookmarks a post.
func CreatePost ¶
func CreatePost(client Client, text string, mediaIDs []string, opts RequestOptions) (json.RawMessage, error)
CreatePost sends a new post and returns the API response.
func DeletePost ¶
func DeletePost(client Client, postID string, opts RequestOptions) (json.RawMessage, error)
DeletePost deletes a post by ID.
func ExecuteMediaStatus ¶
func ExecuteMediaStatus(mediaID, authType, username string, verbose, wait, trace bool, headers []string, client Client) error
ExecuteMediaStatus handles the media status command execution
func ExecuteMediaUpload ¶
func ExecuteMediaUpload(filePath, mediaType, mediaCategory, authType, username string, verbose, waitForProcessing, trace bool, headers []string, client Client) error
ExecuteMediaUpload handles the media upload command execution
func ExecuteRequest ¶
func ExecuteRequest(options RequestOptions, client Client) error
ExecuteRequest handles the execution of a regular API request
func ExecuteStreamRequest ¶
func ExecuteStreamRequest(options RequestOptions, client Client) error
ExecuteStreamRequest handles the execution of a streaming API request
func ExtractMediaID ¶
ExtractMediaID extracts media_id from URL or data
func ExtractSegmentIndex ¶
ExtractSegmentIndex extracts segment_index from URL or data
func FollowUser ¶
func FollowUser(client Client, sourceUserID, targetUserID string, opts RequestOptions) (json.RawMessage, error)
FollowUser follows a user.
func GetBookmarks ¶
func GetBookmarks(client Client, userID string, maxResults int, opts RequestOptions) (json.RawMessage, error)
GetBookmarks fetches the authenticated user's bookmarks.
func GetDMEvents ¶
func GetDMEvents(client Client, maxResults int, opts RequestOptions) (json.RawMessage, error)
GetDMEvents fetches recent DM events.
func GetFollowers ¶
func GetFollowers(client Client, userID string, maxResults int, opts RequestOptions) (json.RawMessage, error)
GetFollowers fetches followers of a given user.
func GetFollowing ¶
func GetFollowing(client Client, userID string, maxResults int, opts RequestOptions) (json.RawMessage, error)
GetFollowing fetches users that a given user follows.
func GetLikedPosts ¶
func GetLikedPosts(client Client, userID string, maxResults int, opts RequestOptions) (json.RawMessage, error)
GetLikedPosts fetches posts liked by a user.
func GetMe ¶
func GetMe(client Client, opts RequestOptions) (json.RawMessage, error)
GetMe fetches the authenticated user's profile.
func GetMentions ¶
func GetMentions(client Client, userID string, maxResults int, opts RequestOptions) (json.RawMessage, error)
GetMentions fetches recent mentions for a user.
func GetTimeline ¶
func GetTimeline(client Client, userID string, maxResults int, opts RequestOptions) (json.RawMessage, error)
GetTimeline fetches the authenticated user's reverse‑chronological timeline. Route: GET /2/users/{id}/timelines/reverse_chronological
func GetUserPosts ¶
func GetUserPosts(client Client, userID string, maxResults int, opts RequestOptions) (json.RawMessage, error)
GetUserPosts fetches recent posts by a user ID.
func HandleMediaAppendRequest ¶
func HandleMediaAppendRequest(options RequestOptions, mediaFile string, client Client) (json.RawMessage, error)
HandleMediaAppendRequest handles a media append request with a file
func HandleRequest ¶
func HandleRequest(options RequestOptions, forceStream bool, mediaFile string, client Client) error
HandleRequest determines the type of request and executes it accordingly
func IsMediaAppendRequest ¶
IsMediaAppendRequest checks if the request is a media append request
func IsStreamingEndpoint ¶
IsStreamingEndpoint checks if an endpoint should be streamed
func LikePost ¶
func LikePost(client Client, userID, postID string, opts RequestOptions) (json.RawMessage, error)
LikePost likes a post on behalf of the authenticated user.
func LookupUser ¶
func LookupUser(client Client, username string, opts RequestOptions) (json.RawMessage, error)
LookupUser fetches a user by username.
func MuteUser ¶
func MuteUser(client Client, sourceUserID, targetUserID string, opts RequestOptions) (json.RawMessage, error)
MuteUser mutes a user.
func QuotePost ¶
func QuotePost(client Client, postID, text string, opts RequestOptions) (json.RawMessage, error)
QuotePost sends a quote post.
func ReadPost ¶
func ReadPost(client Client, postID string, opts RequestOptions) (json.RawMessage, error)
ReadPost fetches a single post with useful expansions.
func ReplyToPost ¶
func ReplyToPost(client Client, postID, text string, mediaIDs []string, opts RequestOptions) (json.RawMessage, error)
ReplyToPost sends a reply to an existing post.
func Repost ¶
func Repost(client Client, userID, postID string, opts RequestOptions) (json.RawMessage, error)
Repost reposts a post.
func ResolvePostID ¶
ResolvePostID extracts a post ID from a full URL or returns the input as‑is. Accepts:
- https://x.com/user/status/123456
- https://x.com/user/status/123456 (legacy domain also works)
- 123456
func ResolveUsername ¶
ResolveUsername normalises a username – strips a leading "@" if present.
func SearchPosts ¶
func SearchPosts(client Client, query string, maxResults int, opts RequestOptions) (json.RawMessage, error)
SearchPosts searches recent posts.
func SendDM ¶
func SendDM(client Client, participantID, text string, opts RequestOptions) (json.RawMessage, error)
SendDM sends a direct message to a user.
func UnblockUser ¶
func UnblockUser(client Client, sourceUserID, targetUserID string, opts RequestOptions) (json.RawMessage, error)
UnblockUser unblocks a user.
func Unbookmark ¶
func Unbookmark(client Client, userID, postID string, opts RequestOptions) (json.RawMessage, error)
Unbookmark removes a bookmark.
func UnfollowUser ¶
func UnfollowUser(client Client, sourceUserID, targetUserID string, opts RequestOptions) (json.RawMessage, error)
UnfollowUser unfollows a user.
func UnlikePost ¶
func UnlikePost(client Client, userID, postID string, opts RequestOptions) (json.RawMessage, error)
UnlikePost unlikes a post.
func UnmuteUser ¶
func UnmuteUser(client Client, sourceUserID, targetUserID string, opts RequestOptions) (json.RawMessage, error)
UnmuteUser unmutes a user.
func Unrepost ¶
func Unrepost(client Client, userID, postID string, opts RequestOptions) (json.RawMessage, error)
Unrepost removes a repost.
Types ¶
type ApiClient ¶
type ApiClient struct {
// contains filtered or unexported fields
}
ApiClient handles API requests
func NewApiClient ¶
NewApiClient creates a new ApiClient
func (*ApiClient) BuildMultipartRequest ¶
func (c *ApiClient) BuildMultipartRequest(options MultipartOptions) (*http.Request, error)
BuildMultipartRequest builds an HTTP request with multipart form data
func (*ApiClient) BuildRequest ¶
func (c *ApiClient) BuildRequest(requestOptions RequestOptions) (*http.Request, error)
BuildRequest builds an HTTP request
func (*ApiClient) SendMultipartRequest ¶
func (c *ApiClient) SendMultipartRequest(options MultipartOptions) (json.RawMessage, error)
SendMultipartRequest sends an HTTP request with multipart form data
func (*ApiClient) SendRequest ¶
func (c *ApiClient) SendRequest(options RequestOptions) (json.RawMessage, error)
SendRequest sends an HTTP request
func (*ApiClient) StreamRequest ¶
func (c *ApiClient) StreamRequest(options RequestOptions) error
StreamRequest sends an HTTP request and streams the response
type Client ¶
type Client interface {
BuildRequest(requestOptions RequestOptions) (*http.Request, error)
BuildMultipartRequest(options MultipartOptions) (*http.Request, error)
SendRequest(options RequestOptions) (json.RawMessage, error)
StreamRequest(options RequestOptions) error
SendMultipartRequest(options MultipartOptions) (json.RawMessage, error)
}
Client is an interface for API clients
type InitRequest ¶
type MediaUploader ¶
type MediaUploader struct {
// contains filtered or unexported fields
}
MediaUploader handles media upload operations
func NewMediaUploader ¶
func NewMediaUploader(client Client, filePath string, verbose, trace bool, authType string, username string, headers []string) (*MediaUploader, error)
NewMediaUploader creates a new MediaUploader
func (*MediaUploader) Append ¶
func (m *MediaUploader) Append() error
Append uploads the media in chunks
func (*MediaUploader) CheckStatus ¶
func (m *MediaUploader) CheckStatus() (json.RawMessage, error)
CheckStatus checks the status of the media upload
func (*MediaUploader) Finalize ¶
func (m *MediaUploader) Finalize() (json.RawMessage, error)
Finalize finalizes the media upload
func (*MediaUploader) GetMediaID ¶
func (m *MediaUploader) GetMediaID() string
GetMediaID returns the media ID
func (*MediaUploader) Init ¶
func (m *MediaUploader) Init(mediaType string, mediaCategory string) error
Init initializes the media upload
func (*MediaUploader) SetMediaID ¶
func (m *MediaUploader) SetMediaID(mediaID string)
SetMediaID sets the media ID
func (*MediaUploader) WaitForProcessing ¶
func (m *MediaUploader) WaitForProcessing() (json.RawMessage, error)
WaitForProcessing waits for media processing to complete
type MultipartOptions ¶
type MultipartOptions struct {
RequestOptions
FormFields map[string]string
FileField string
FilePath string
FileName string
FileData []byte
}
MultipartOptions contains options specific to multipart requests
type PostBody ¶
type PostBody struct {
Text string `json:"text"`
Reply *PostReply `json:"reply,omitempty"`
Quote *string `json:"quote_tweet_id,omitempty"` // API field name — do not rename
Media *PostMedia `json:"media,omitempty"`
Poll *PostPoll `json:"poll,omitempty"`
}
PostBody is the JSON body for POST /2/tweets
type PostMedia ¶
type PostMedia struct {
MediaIDs []string `json:"media_ids"`
}
PostMedia nests inside PostBody to attach uploaded media
type PostPoll ¶
type PostPoll struct {
Options []string `json:"options"`
DurationMinutes int `json:"duration_minutes"`
}
PostPoll nests inside PostBody to create a poll