models

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	QueryIDLike      = "lI07N6Otwv1PhnEgXILM7A"
	QueryIDUnlike    = "ZYKSe-w7KEslx3JhSIk5LA"
	QueryIDRetweet   = "ojPdsZsimiJrUGLR1sjUtA"
	QueryIDUnretweet = "iQtK4dl5hBmXewYZLkNG9A"
	QueryIDTweet     = "bDE2rBtZb3uyrczSZ_pI9g"
)

Query IDs for different operations

View Source
const (
	BearerToken = "Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA"
)

API Constants

View Source
const (
	UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36"
)

User Agent

Variables

View Source
var (
	ErrAccountLocked = errors.New("account is temporarily locked")
	ErrAuthFailed    = errors.New("authentication failed")
	ErrInvalidToken  = errors.New("invalid token")
	ErrUnknown       = errors.New("unable to complete operation")
)

Common error types for Twitter operations

Functions

This section is empty.

Types

type Account

type Account struct {
	Ct0       string // CSRF token
	AuthToken string // auth_token cookie
	Proxy     string // Format: "ip:port" or "user:pass@ip:port"

	// Account Info
	Username      string
	DisplayName   string
	UserID        string
	Email         string
	PhoneNumber   string
	IsVerified    bool
	CreatedAt     string
	FollowCount   int
	FollowerCount int

	// Session Data
	Cookies []*http.Cookie

	// Optional fields
	ProfileImageURL string
	Bio             string
	Location        string
	Website         string

	Suspended bool
	Locked    bool
}

Account represents a Twitter account with all necessary credentials and information

type AccountInfoResponse

type AccountInfoResponse struct {
	ID                int64  `json:"id"`
	IDStr             string `json:"id_str"`
	Name              string `json:"name"`
	ScreenName        string `json:"screen_name"`
	Location          string `json:"location"`
	Description       string `json:"description"`
	FollowersCount    int    `json:"followers_count"`
	FriendsCount      int    `json:"friends_count"`
	ListedCount       int    `json:"listed_count"`
	CreatedAt         string `json:"created_at"`
	FavouritesCount   int    `json:"favourites_count"`
	StatusesCount     int    `json:"statuses_count"`
	MediaCount        int    `json:"media_count"`
	Protected         bool   `json:"protected"`
	Verified          bool   `json:"verified"`
	Suspended         bool   `json:"suspended"`
	Following         bool   `json:"following"`
	FollowedBy        bool   `json:"followed_by"`
	FollowRequestSent bool   `json:"follow_request_sent"`
}

AccountInfoResponse represents the response from Twitter's user lookup endpoint

type ActionResponse

type ActionResponse struct {
	Success bool
	Error   error
	Status  ActionStatus
}

ActionResponse represents the response from any Twitter action

type ActionStatus

type ActionStatus int

ActionStatus represents the status of any Twitter action (like, retweet, etc.)

const (
	StatusSuccess      ActionStatus = iota
	StatusAlreadyDone               // Already liked, already retweeted, etc.
	StatusLocked                    // Account is locked
	StatusNotFound                  // Tweet/User not found
	StatusRateLimited               // Rate limit exceeded
	StatusAuthError                 // Authentication error
	StatusInvalidToken              // Invalid token
	StatusUnknown                   // Unknown error
)

type AlreadyLikedResponse

type AlreadyLikedResponse struct {
	Errors []struct {
		Message   string `json:"message"`
		Locations []struct {
			Line   int `json:"line"`
			Column int `json:"column"`
		} `json:"locations"`
		Path       []string `json:"path"`
		Extensions struct {
			Name    string `json:"name"`
			Source  string `json:"source"`
			Code    int    `json:"code"`
			Kind    string `json:"kind"`
			Tracing struct {
				TraceID string `json:"trace_id"`
			} `json:"tracing"`
		} `json:"extensions"`
	} `json:"errors"`
}

AlreadyLikedResponse represents the response when tweet is already liked

type Config

type Config struct {
	// HTTP Client settings
	MaxRetries      int
	Timeout         time.Duration
	FollowRedirects bool

	// Logging options
	LogLevel utils.LogLevel // Level of logging detail

	// Twitter Constants
	Constants TwitterConstants
}

Config holds Twitter client configuration

func NewConfig

func NewConfig() *Config

NewConfig returns a Config with default settings

type LikeGraphQLResponse

type LikeGraphQLResponse struct {
	Data struct {
		FavoriteTweet string `json:"favorite_tweet"`
	} `json:"data"`
	Errors []struct {
		Message   string `json:"message"`
		Locations []struct {
			Line   int `json:"line"`
			Column int `json:"column"`
		} `json:"locations"`
		Path       []string `json:"path"`
		Extensions struct {
			Name    string `json:"name"`
			Source  string `json:"source"`
			Code    int    `json:"code"`
			Kind    string `json:"kind"`
			Tracing struct {
				TraceID string `json:"trace_id"`
			} `json:"tracing"`
		} `json:"extensions"`
	} `json:"errors"`
}

LikeGraphQLResponse represents the GraphQL response for a like action

type LikeResponse

type LikeResponse struct {
	Success bool
	Error   error
	Status  LikeStatus
}

LikeResponse represents the response from a like action

type LikeStatus

type LikeStatus int

LikeStatus represents the status of a like action

const (
	LikeStatusSuccess LikeStatus = iota
	LikeStatusAlreadyLiked
	LikeStatusTweetNotFound
	LikeStatusRateLimited
	LikeStatusAuthError
	LikeStatusUnknown
)

type MediaUploadResponse

type MediaUploadResponse struct {
	MediaIDString string `json:"media_id_string"`
	Size          int    `json:"size"`
	ExpiresAfter  int    `json:"expires_after_secs"`
}

MediaUploadResponse represents the response from media upload

type RetweetGraphQLResponse

type RetweetGraphQLResponse struct {
	Data struct {
		CreateRetweet struct {
			RetweetResults struct {
				Result struct {
					RestID string `json:"rest_id"`
					Legacy struct {
						FullText string `json:"full_text"`
					} `json:"legacy"`
				} `json:"result"`
			} `json:"retweet_results"`
		} `json:"create_retweet"`
	} `json:"data"`
	Errors []struct {
		Message   string `json:"message"`
		Locations []struct {
			Line   int `json:"line"`
			Column int `json:"column"`
		} `json:"locations"`
		Path       []string `json:"path"`
		Extensions struct {
			Name    string `json:"name"`
			Source  string `json:"source"`
			Code    int    `json:"code"`
			Kind    string `json:"kind"`
			Tracing struct {
				TraceID string `json:"trace_id"`
			} `json:"tracing"`
		} `json:"extensions"`
	} `json:"errors"`
}

RetweetGraphQLResponse represents the GraphQL response for a retweet action

type Tweet

type Tweet struct {
	ID              string
	AuthorUsername  string
	AuthorID        string
	Text            string
	CreatedAt       string
	LikeCount       int
	RetweetCount    int
	QuoteCount      int
	ReplyCount      int
	IsLiked         bool
	IsRetweeted     bool
	IsQuoted        bool
	IsReply         bool
	ConversationID  string
	InReplyToUserID string
}

Tweet represents a Twitter tweet with its basic information

type TweetGraphQLResponse

type TweetGraphQLResponse struct {
	Data struct {
		CreateTweet struct {
			TweetResults struct {
				Result struct {
					RestID string `json:"rest_id"`
				} `json:"result"`
			} `json:"tweet_results"`
		} `json:"create_tweet"`
	} `json:"data"`
	Errors []struct {
		Message   string `json:"message"`
		Locations []struct {
			Line   int `json:"line"`
			Column int `json:"column"`
		} `json:"locations"`
		Path       []string `json:"path"`
		Extensions struct {
			Name    string `json:"name"`
			Source  string `json:"source"`
			Code    int    `json:"code"`
			Kind    string `json:"kind"`
			Tracing struct {
				TraceID string `json:"trace_id"`
			} `json:"tracing"`
		} `json:"extensions"`
	} `json:"errors"`
}

TweetGraphQLResponse represents the GraphQL response for a tweet action

type TwitterConstants

type TwitterConstants struct {
	// API Constants
	BearerToken string
	UserAgent   string

	// Query IDs
	QueryID struct {
		Like      string
		Unlike    string
		Retweet   string
		Unretweet string
		Tweet     string
	}
}

TwitterConstants holds all Twitter-specific constants

type UnlikeGraphQLResponse

type UnlikeGraphQLResponse struct {
	Data struct {
		UnfavoriteTweet string `json:"unfavorite_tweet"`
	} `json:"data"`
	Errors []struct {
		Message   string `json:"message"`
		Locations []struct {
			Line   int `json:"line"`
			Column int `json:"column"`
		} `json:"locations"`
		Path       []string `json:"path"`
		Extensions struct {
			Name    string `json:"name"`
			Source  string `json:"source"`
			Code    int    `json:"code"`
			Kind    string `json:"kind"`
			Tracing struct {
				TraceID string `json:"trace_id"`
			} `json:"tracing"`
		} `json:"extensions"`
	} `json:"errors"`
}

UnlikeGraphQLResponse represents the GraphQL response for an unlike action

type UnretweetGraphQLResponse

type UnretweetGraphQLResponse struct {
	Data struct {
		Unretweet struct {
			SourceTweetResults struct {
				Result struct {
					RestID string `json:"rest_id"`
					Legacy struct {
						FullText string `json:"full_text"`
					} `json:"legacy"`
				} `json:"result"`
			} `json:"source_tweet_results"`
		} `json:"unretweet"`
	} `json:"data"`
	Errors []struct {
		Message   string `json:"message"`
		Locations []struct {
			Line   int `json:"line"`
			Column int `json:"column"`
		} `json:"locations"`
		Path       []string `json:"path"`
		Extensions struct {
			Name    string `json:"name"`
			Source  string `json:"source"`
			Code    int    `json:"code"`
			Kind    string `json:"kind"`
			Tracing struct {
				TraceID string `json:"trace_id"`
			} `json:"tracing"`
		} `json:"extensions"`
	} `json:"errors"`
}

UnretweetGraphQLResponse represents the GraphQL response for an unretweet action

type UserResponse

type UserResponse struct {
	ID                int64  `json:"id"`
	IDStr             string `json:"id_str"`
	Name              string `json:"name"`
	ScreenName        string `json:"screen_name"`
	Location          string `json:"location"`
	Description       string `json:"description"`
	URL               any    `json:"url"`
	Protected         bool   `json:"protected"`
	FollowersCount    int    `json:"followers_count"`
	FriendsCount      int    `json:"friends_count"`
	ListedCount       int    `json:"listed_count"`
	CreatedAt         string `json:"created_at"`
	FavouritesCount   int    `json:"favourites_count"`
	Verified          bool   `json:"verified"`
	StatusesCount     int    `json:"statuses_count"`
	MediaCount        int    `json:"media_count"`
	Following         bool   `json:"following"`
	FollowRequestSent bool   `json:"follow_request_sent"`
	Notifications     bool   `json:"notifications"`
	Entities          struct {
		Description struct {
			Urls []any `json:"urls"`
		} `json:"description"`
	} `json:"entities"`
}

UserResponse represents the response from Twitter's user-related endpoints

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL