Documentation
¶
Index ¶
- func NewAccount(authToken, ct0, proxy string) *models.Account
- type AccountInfo
- type CommentOptions
- type MultiUserResponse
- type TweetOptions
- type Twitter
- func (t *Twitter) Comment(content string, tweetID string, opts *CommentOptions) *models.ActionResponse
- func (t *Twitter) Follow(username string) *models.ActionResponse
- func (t *Twitter) GetUserInfoByUsername(username string) (*UserInfoResponse, *models.ActionResponse)
- func (t *Twitter) IsValid() (*AccountInfo, *models.ActionResponse)
- func (t *Twitter) Like(tweetID string) *models.ActionResponse
- func (t *Twitter) Retweet(tweetID string) *models.ActionResponse
- func (t *Twitter) Tweet(content string, opts *TweetOptions) *models.ActionResponse
- func (t *Twitter) Unfollow(userIDOrUsername string) *models.ActionResponse
- func (t *Twitter) UploadMedia(mediaBase64 string) (string, error)
- func (t *Twitter) VotePoll(tweetID string, answer string) *models.ActionResponse
- type User
- type UserInfoResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewAccount ¶
NewAccount creates a new Twitter account instance.
Parameters:
- authToken: the auth token for the account (required)
- ct0: the x-csrf-token for the account (optional, "" by default)
- proxy: the proxy in user:pass@host:port format (optional, "" by default)
Returns:
- Account: the configured account instance
Example:
// Create account with just auth token account := twitter.NewAccount("auth_token_here", "", "") // Create account with auth token and proxy account := twitter.NewAccount("auth_token_here", "", "user:pass@host:port") // Create account with all parameters account := twitter.NewAccount("auth_token_here", "csrf_token", "user:pass@host:port")
Types ¶
type AccountInfo ¶
type AccountInfo struct { Name string Username string CreationDate string Suspended bool Protected bool Verified bool FollowedBy bool Followers int IsFollowing bool FriendsCount int TweetCount int }
AccountInfo represents detailed information about a Twitter account
type CommentOptions ¶
type CommentOptions struct {
MediaBase64 string // Base64 encoded media (optional)
}
CommentOptions contains optional parameters for creating a comment. Currently supports adding media (images) to comments.
type MultiUserResponse ¶
type MultiUserResponse struct {
Users []User `json:"users"`
}
MultiUserResponse represents the response from Twitter's multi-user list endpoint
type TweetOptions ¶
type TweetOptions struct { QuoteTweetURL string // URL of tweet to quote (optional) MediaBase64 string // Base64 encoded media (optional) }
TweetOptions contains optional parameters for creating a tweet
type Twitter ¶
type Twitter struct { Account *models.Account Client tlsClient.HttpClient Logger utils.Logger Config *models.Config Cookies *utils.CookieClient }
Twitter represents a Twitter API client instance
func NewTwitter ¶
NewTwitter creates a new Twitter API client instance
func (*Twitter) Comment ¶
func (t *Twitter) Comment(content string, tweetID string, opts *CommentOptions) *models.ActionResponse
Comment adds a comment to a tweet with optional media attachment.
Parameters:
- content: the text content of the comment
- tweetID: the ID or URL of the tweet to comment on
- opts: optional parameters like media (can be nil)
Returns an ActionResponse containing:
- Success: true if comment was posted
- Error: any error that occurred
- Status: the status of the action
Example:
// Simple comment resp := twitter.Comment("Great tweet!", "1234567890", nil) // Comment with media resp := twitter.Comment("Check this out!", "1234567890", &CommentOptions{ MediaBase64: imageBase64, }) if resp.Success { fmt.Println("Successfully posted comment") }
func (*Twitter) Follow ¶
func (t *Twitter) Follow(username string) *models.ActionResponse
Follow follows a user by their username.
Parameters:
- username: the Twitter username to follow
Returns an ActionResponse containing:
- Success: true if follow was successful
- Error: any error that occurred
- Status: the status of the action (Success, AuthError, etc.)
Example:
resp := twitter.Follow("username") if resp.Success { fmt.Println("Successfully followed user") }
func (*Twitter) GetUserInfoByUsername ¶
func (t *Twitter) GetUserInfoByUsername(username string) (*UserInfoResponse, *models.ActionResponse)
GetUserInfoByUsername retrieves detailed information about any Twitter user by their username.
Parameters:
- username: the Twitter username to look up
Returns:
- UserInfoResponse: containing detailed user information like:
- User ID and screen name
- Profile information
- Account statistics
- ActionResponse: containing:
- Success: true if lookup was successful
- Error: any error that occurred
- Status: the status of the action
Example:
info, resp := twitter.GetUserInfoByUsername("username") if resp.Success { fmt.Printf("User ID: %s\n", info.Data.User.Result.RestID) fmt.Printf("Followers: %d\n", info.Data.User.Result.Legacy.FollowersCount) }
func (*Twitter) IsValid ¶
func (t *Twitter) IsValid() (*AccountInfo, *models.ActionResponse)
IsValid checks if the account is valid and retrieves its status.
Returns:
- AccountInfo: containing account details like:
- Username and display name
- Account status (suspended, protected, verified)
- ActionResponse: containing:
- Success: true if check was successful
- Error: any error that occurred
- Status: the status of the action
Example:
info, resp := twitter.IsValid() if resp.Success { if info.Suspended { fmt.Println("Account is suspended") } else { fmt.Printf("Account %s is valid\n", info.Username) } }
func (*Twitter) Like ¶
func (t *Twitter) Like(tweetID string) *models.ActionResponse
Like adds a like to a tweet tweetID can be either a tweet URL or tweet ID
func (*Twitter) Retweet ¶
func (t *Twitter) Retweet(tweetID string) *models.ActionResponse
Retweet retweets a tweet tweetID can be either a tweet URL or tweet ID
func (*Twitter) Tweet ¶
func (t *Twitter) Tweet(content string, opts *TweetOptions) *models.ActionResponse
Tweet posts a new tweet with optional media or quote functionality.
Examples:
Regular tweet:
twitter.Tweet("Hello, world!", nil)
Tweet with media:
twitter.Tweet("Check out this image!", &TweetOptions{ MediaBase64: imageBase64String, })
Quote tweet:
twitter.Tweet("Look at this!", &TweetOptions{ QuoteTweetURL: "https://twitter.com/user/status/123456789", })
Tweet with both media and quote:
twitter.Tweet("Amazing!", &TweetOptions{ MediaBase64: imageBase64String, QuoteTweetURL: "https://twitter.com/user/status/123456789", })
Parameters:
- content: The text content of the tweet
- opts: Optional parameters for media and quote tweets (can be nil)
Returns:
- *models.ActionResponse containing the success status and any errors
func (*Twitter) Unfollow ¶
func (t *Twitter) Unfollow(userIDOrUsername string) *models.ActionResponse
Unfollow unfollows a user by their user ID or username.
Parameters:
- userIDOrUsername: can be either a numeric user ID or a Twitter username
Returns an ActionResponse containing:
- Success: true if unfollow was successful
- Error: any error that occurred
- Status: the status of the action (Success, AuthError, etc.)
Example:
// Unfollow by username resp := twitter.Unfollow("username") // Unfollow by ID resp := twitter.Unfollow("1234567890") if resp.Success { fmt.Println("Successfully unfollowed user") }
func (*Twitter) UploadMedia ¶
UploadMedia uploads media to Twitter and returns the media ID. Used internally by Tweet and Comment functions when including media.
Parameters:
- mediaBase64: the base64-encoded image data
Returns:
- string: the media ID if successful
- error: any error that occurred
Example:
mediaID, err := twitter.UploadMedia(imageBase64) if err != nil { log.Fatal(err) } // Use mediaID in Tweet or Comment function
type User ¶
type User struct { UserID string `json:"user_id"` Name string `json:"name"` ScreenName string `json:"screen_name"` AvatarURL string `json:"avatar_image_url"` IsSuspended bool `json:"is_suspended"` IsVerified bool `json:"is_verified"` IsProtected bool `json:"is_protected"` IsAuthValid bool `json:"is_auth_valid"` }
User represents a user entry in the multi-user response
type UserInfoResponse ¶
type UserInfoResponse struct { Data struct { User struct { Result struct { RestID string `json:"rest_id"` Legacy struct { Following bool `json:"following"` CreatedAt string `json:"created_at"` Description string `json:"description"` FavouritesCount int `json:"favourites_count"` FollowersCount int `json:"followers_count"` FriendsCount int `json:"friends_count"` ListedCount int `json:"listed_count"` Location string `json:"location"` MediaCount int `json:"media_count"` Name string `json:"name"` NormalFollowersCount int `json:"normal_followers_count"` ScreenName string `json:"screen_name"` StatusesCount int `json:"statuses_count"` Verified bool `json:"verified"` } `json:"legacy"` IsBlueVerified bool `json:"is_blue_verified"` } `json:"result"` } `json:"user"` } `json:"data"` }
UserInfoResponse represents the GraphQL response for user info