twitter

package
v0.9.9 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package twitter fetches Twitter/X user profile data using authenticated session cookies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthRequired

func AuthRequired() bool

AuthRequired returns true because Twitter requires authentication.

func IsValidProfileURL

func IsValidProfileURL(urlStr string) bool

IsValidProfileURL validates that a Twitter/X URL points to an actual user profile, filtering out system pages, language codes, and invalid usernames.

func IsValidUsername

func IsValidUsername(username string) bool

IsValidUsername validates a Twitter username against platform requirements. Twitter usernames must be 1-15 characters and contain only alphanumeric or underscore.

func Match

func Match(urlStr string) bool

Match returns true if the URL is a Twitter/X profile URL.

Types

type Client

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

Client handles Twitter/X requests with authenticated cookies.

func New

func New(ctx context.Context, opts ...Option) (*Client, error)

New creates a Twitter client. Cookie sources: WithCookies > environment variables > browser. If no cookies are available, the client will still work using the FXTwitter public API fallback.

func (*Client) EnableDebug

func (c *Client) EnableDebug()

EnableDebug enables debug logging.

func (*Client) Fetch

func (c *Client) Fetch(ctx context.Context, urlStr string) (*profile.Profile, error)

Fetch retrieves a Twitter profile using GraphQL API.

type Option

type Option func(*config)

Option configures a Client.

func WithBrowserCookies

func WithBrowserCookies() Option

WithBrowserCookies enables reading cookies from browser stores.

func WithCookies

func WithCookies(cookies map[string]string) Option

WithCookies sets explicit cookie values.

func WithHTTPCache

func WithHTTPCache(httpCache httpcache.Cacher) Option

WithHTTPCache sets the HTTP cache.

func WithLogger

func WithLogger(logger *slog.Logger) Option

WithLogger sets a custom logger.

Jump to

Keyboard shortcuts

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