twittermeow

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: AGPL-3.0 Imports: 32 Imported by: 0

README

x-go

A Go library for interacting with X's API

Test steps
  1. Create cookies.txt in this directory, grab your cookie string from x.com and paste it there
  2. Run go test client_test.go -v
Testing functionality
	_, _, err = cli.LoadMessagesPage()
	if err != nil {
		log.Fatal(err)
	}

The LoadMessagesPage method makes a request to https://x.com/messages then makes 2 calls:

	data, err := c.GetAccountSettings(...)
	initialInboxState, err := c.GetInitialInboxState(...)

it sets up the current "page" session for the client, fetches the current authenticated user info as well as the initial inbox state (the very starting inbox information you see when u load /messages) then returns the parsed data.

To easily test with the available functions I have made, lets say you wanna test uploading an image and sending it to the top conversation in your inbox you could simply do something like:

	initialInboxData, _, err := cli.LoadMessagesPage()
	if err != nil {
		log.Fatal(err)
	}
    	uploadAndSendImageTest(initialInboxData)

Or feel free to try it out yourself! All the methods are available on the client instance.

Documentation

Index

Constants

View Source
const BrowserName = "Chrome"
View Source
const ChromeVersion = "131"
View Source
const ChromeVersionFull = ChromeVersion + ".0.6778.85"
View Source
const MaxHTTPRetries = 5
View Source
const OSName = "Linux"
View Source
const OSVersion = "6.8.0"
View Source
const SecCHFullVersionList = `"Chromium";v="` + ChromeVersionFull + `", "Google Chrome";v="` + ChromeVersionFull + `", "Not-A.Brand";v="99.0.0.0"`
View Source
const SecCHMobile = "?0"
View Source
const SecCHModel = ""
View Source
const SecCHPlatform = `"` + OSName + `"`
View Source
const SecCHPlatformVersion = `"` + OSVersion + `"`
View Source
const SecCHPrefersColorScheme = "light"
View Source
const SecCHUserAgent = `"Chromium";v="` + ChromeVersion + `", "Google Chrome";v="` + ChromeVersion + `", "Not-A.Brand";v="99"`
View Source
const UDID = OSName + "/" + BrowserName
View Source
const UserAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/" + ChromeVersion + ".0.0.0 Safari/537.36"

Variables

View Source
var (
	ErrConnectSetEventHandler = errors.New("event handler must be set before connecting")
	ErrNotAuthenticatedYet    = errors.New("client has not been authenticated yet")

	ErrAlreadyPollingUpdates = errors.New("client is already polling for user updates")
	ErrNotPollingUpdates     = errors.New("client is not polling for user updates")
)
View Source
var (
	ErrCouldNotAuthenticate     error = TwitterError{Code: 32}
	ErrUserSuspended            error = TwitterError{Code: 63}
	ErrAccountSuspended         error = TwitterError{Code: 63}
	ErrNotActive                error = TwitterError{Code: 141}
	ErrAccountTemporarilyLocked error = TwitterError{Code: 326}
)
View Source
var (
	ErrRedirectAttempted   = errors.New("redirect attempted")
	ErrRequestCreateFailed = errors.New("failed to create request")
	ErrRequestFailed       = errors.New("failed to send request")
	ErrResponseReadFailed  = errors.New("failed to read response body")
	ErrMaxRetriesReached   = errors.New("maximum retries reached")
)
View Source
var BaseHeaders = http.Header{
	"Accept":             []string{"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"},
	"Accept-Language":    []string{"en-US,en;q=0.9"},
	"User-Agent":         []string{UserAgent},
	"Sec-Ch-Ua":          []string{SecCHUserAgent},
	"Sec-Ch-Ua-Platform": []string{SecCHPlatform},
	"Sec-Ch-Ua-Mobile":   []string{SecCHMobile},
	"Referer":            []string{endpoints.BASE_URL + "/"},
	"Origin":             []string{endpoints.BASE_URL},
}

Functions

func IsAuthError

func IsAuthError(err error) bool

Types

type Client

type Client struct {
	Logger zerolog.Logger

	HTTP *http.Client
	// contains filtered or unexported fields
}

func NewClient

func NewClient(opts *ClientOpts, logger zerolog.Logger) *Client

func (*Client) Connect

func (c *Client) Connect() error

func (*Client) DeleteConversation

func (c *Client) DeleteConversation(conversationID string, payload *payload.DMRequestQuery) error

func (*Client) DeleteMessageForMe

keep in mind this only deletes the message for you

func (*Client) Disconnect

func (c *Client) Disconnect() error

func (*Client) EditDirectMessage

func (c *Client) EditDirectMessage(payload *payload.EditDirectMessagePayload) (*types.Message, error)

func (*Client) FetchConversationContext

func (c *Client) FetchConversationContext(conversationID string, params *payload.DMRequestQuery, context payload.ContextInfo) (*response.ConversationDMResponse, error)

func (*Client) FetchTrustedThreads

func (c *Client) FetchTrustedThreads(params *payload.DMRequestQuery) (*response.InboxTimelineResponse, error)

func (*Client) GetAccountSettings

func (c *Client) GetAccountSettings(params payload.AccountSettingsQuery) (*response.AccountSettingsResponse, error)

func (*Client) GetCookieString

func (c *Client) GetCookieString() string

func (*Client) GetCurrentUser

func (c *Client) GetCurrentUser() *response.AccountSettingsResponse

func (*Client) GetCurrentUserID

func (c *Client) GetCurrentUserID() string

func (*Client) GetDMPermissions

func (*Client) GetDMUserUpdates

func (c *Client) GetDMUserUpdates(params *payload.DMRequestQuery) (*response.GetDMUserUpdatesResponse, error)

func (*Client) GetInitialInboxState

func (c *Client) GetInitialInboxState(params *payload.DMRequestQuery) (*response.InboxInitialStateResponse, error)

func (*Client) GetMediaUploadStatus

func (c *Client) GetMediaUploadStatus(mediaID string, h http.Header) (*response.FinalizedUploadMediaResponse, []byte, error)

func (*Client) IsLoggedIn

func (c *Client) IsLoggedIn() bool

func (*Client) Login

func (c *Client) Login() error

func (*Client) Logout

func (c *Client) Logout() (bool, error)

func (*Client) MakeRequest

func (c *Client) MakeRequest(url string, method string, headers http.Header, payload []byte, contentType types.ContentType) (*http.Response, []byte, error)

func (*Client) MarkConversationRead

func (c *Client) MarkConversationRead(params *payload.MarkConversationReadQuery) error

func (*Client) PinConversation

func (c *Client) PinConversation(conversationID string) (*response.PinConversationResponse, error)

func (*Client) React

func (c *Client) React(reactionPayload *payload.ReactionActionPayload, remove bool) (*response.ReactionResponse, error)

func (*Client) Search

func (c *Client) Search(params payload.SearchQuery) (*response.SearchResponse, error)

func (*Client) SendDirectMessage

func (c *Client) SendDirectMessage(pl *payload.SendDirectMessagePayload) (*response.XInboxData, error)

func (*Client) SendTypingNotification

func (c *Client) SendTypingNotification(conversationID string) error

func (*Client) SetEventHandler

func (c *Client) SetEventHandler(handler EventHandler)

func (*Client) SetProxy

func (c *Client) SetProxy(proxyAddr string) error

func (*Client) SetPushNotificationConfig

func (c *Client) SetPushNotificationConfig(setting PushNotificationSetting, config WebPushConfig) error

func (*Client) UnpinConversation

func (c *Client) UnpinConversation(conversationID string) (*response.UnpinConversationResponse, error)

func (*Client) UploadMedia

func (c *Client) UploadMedia(params *payload.UploadMediaQuery, mediaBytes []byte) (*response.FinalizedUploadMediaResponse, error)

type ClientOpts

type ClientOpts struct {
	PollingInterval *time.Duration
	Cookies         *cookies.Cookies
	Session         *SessionLoader
	EventHandler    EventHandler
	WithJOTClient   bool
}

type EventHandler

type EventHandler func(evt any)

type HeaderOpts

type HeaderOpts struct {
	WithAuthBearer      bool
	WithNonAuthBearer   bool
	WithCookies         bool
	WithXGuestToken     bool
	WithXTwitterHeaders bool
	WithXCsrfToken      bool
	WithXClientUUID     bool
	Referer             string
	Origin              string
	Extra               map[string]string
}

type JotClient

type JotClient struct {
	// contains filtered or unexported fields
}

type OnboardingClient

type OnboardingClient struct {
	// contains filtered or unexported fields
}

func (*OnboardingClient) SetCurrentTasks

func (o *OnboardingClient) SetCurrentTasks(tasks *types.TaskResponse)

func (*OnboardingClient) SetFlowToken

func (o *OnboardingClient) SetFlowToken(flowToken string) *OnboardingClient

type PollingClient

type PollingClient struct {
	// contains filtered or unexported fields
}

func (*PollingClient) SetCurrentCursor

func (pc *PollingClient) SetCurrentCursor(cursor string)

type PushNotificationSetting

type PushNotificationSetting int
const (
	REGISTER_PUSH   PushNotificationSetting = 0
	UNREGISTER_PUSH PushNotificationSetting = 1
)

type SessionAuthTokens

type SessionAuthTokens struct {
	// contains filtered or unexported fields
}

type SessionLoader

type SessionLoader struct {
	// contains filtered or unexported fields
}

func (*SessionLoader) CalculateAnimationToken added in v0.2.1

func (s *SessionLoader) CalculateAnimationToken()

func (*SessionLoader) GetAuthTokens

func (s *SessionLoader) GetAuthTokens() *SessionAuthTokens

func (*SessionLoader) GetCountry

func (s *SessionLoader) GetCountry() string

func (*SessionLoader) GetCurrentUser

func (s *SessionLoader) GetCurrentUser() *response.AccountSettingsResponse

func (*SessionLoader) GetVerificationToken

func (s *SessionLoader) GetVerificationToken() string

func (*SessionLoader) LoadPage

func (s *SessionLoader) LoadPage(url string) error

func (*SessionLoader) SetAuthTokens

func (s *SessionLoader) SetAuthTokens(authenticatedToken, notAuthenticatedToken string)

func (*SessionLoader) SetCountry

func (s *SessionLoader) SetCountry(country string)

func (*SessionLoader) SetCurrentUser

func (s *SessionLoader) SetCurrentUser(data *response.AccountSettingsResponse)

func (*SessionLoader) SetVariableIndexes added in v0.2.1

func (s *SessionLoader) SetVariableIndexes(indexes *[4]int)

func (*SessionLoader) SetVerificationToken

func (s *SessionLoader) SetVerificationToken(verificationToken string, anims *[4][16][11]int)

type TwitterError

type TwitterError struct {
	Message string `json:"message"`
	Code    int    `json:"code"`
}

func (TwitterError) Error

func (te TwitterError) Error() string

func (TwitterError) Is

func (te TwitterError) Is(other error) bool

type TwitterErrors

type TwitterErrors struct {
	Errors []TwitterError `json:"errors"`
}

func (*TwitterErrors) Error

func (te *TwitterErrors) Error() string

func (*TwitterErrors) Unwrap

func (te *TwitterErrors) Unwrap() []error

type WebPushConfig

type WebPushConfig struct {
	Endpoint string
	P256DH   []byte
	Auth     []byte
}

Directories

Path Synopsis
data

Jump to

Keyboard shortcuts

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