Documentation
¶
Overview ¶
Package parser implements the w_popularity x (Twitter) adapter.
History: an earlier revision scraped public Nitter mirrors. As of 2026 every public Nitter mirror returns 5xx, Anubis challenges, or DNS failures from server environments, so that approach has been abandoned.
Strategy (tried in order):
Official X API v2 (preferred). Requires Config.BearerToken (or env X_BEARER_TOKEN). One GET /2/users/by/username/<handle> with public_metrics gives Followers / PostsCount / TotalLikes. Free tier: 100 user reads / month / app — fine for daily snapshots.
cdn.syndication.twimg.com/timeline/profile (no auth). Twitter's embed-syndication CDN. When it serves a body, the JSON wraps an HTML page containing an `__INITIAL_STATE__` blob with the user payload. The endpoint has been ratcheted down to empty bodies since ~2024 but we still try it: when it works it is the cheapest unauthenticated path.
api.fxtwitter.com (third-party proxy). Reliable JSON-only proxy returning followers / following / tweets / likes / verification. Owned by FixTweet; rate-limited but free.
camoufox-driven browser fallback. Not yet wired — `Config.CamoufoxURL` is reserved for that path. When set we return an explicit "not implemented" hint so the caller can decide whether to escalate to a manual / staffed fallback.
Index ¶
Constants ¶
const DefaultUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) " +
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"
DefaultUserAgent is sent on every unauthenticated request. Some endpoints (notably cdn.syndication.twimg.com) reject bare Go clients with empty bodies, so we mimic a recent desktop browser.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
BearerToken string
HTTPClient *http.Client
HTTPTimeout time.Duration
UserAgent string
CamoufoxURL string
APIBaseURL string
SyndicationURL string
FxTwitterURL string
// Deprecated. Accepted but ignored. Will be removed.
NitterMirrors []string
}
Config controls runtime behaviour.
- BearerToken: X API v2 bearer (free-tier OAuth 2.0 app token). When non-empty the API v2 path is tried first.
- HTTPClient: optional; constructed from HTTPTimeout otherwise.
- HTTPTimeout: per-request budget. Default: 15s.
- UserAgent: overrides DefaultUserAgent.
- CamoufoxURL: reserved for a future browser-driven fallback. Not yet consumed by this implementation.
- APIBaseURL: override https://api.x.com (test hook).
- SyndicationURL: override https://cdn.syndication.twimg.com (test hook).
- FxTwitterURL: override https://api.fxtwitter.com (test hook).
- NitterMirrors: accepted for backward compatibility, IGNORED at runtime. Public Nitter mirrors are no longer reliable; the field is kept so existing configs do not fail to parse.
type XParser ¶
type XParser struct {
// contains filtered or unexported fields
}
XParser is the X (Twitter) adapter.
func (*XParser) FetchChannel ¶
FetchChannel tries each strategy in order until one returns a populated snapshot. See package doc for the priority list.
func (*XParser) FetchRecentPosts ¶
func (p *XParser) FetchRecentPosts(ctx context.Context, handle string, since time.Time) ([]shared.PostSnapshot, error)
FetchRecentPosts returns recent posts. Only the API v2 path returns engagement metrics; the public unauthenticated paths return URL + ID + PublishedAt and leave Likes/Views/Comments at zero (or just return empty when the path cannot reach the user timeline).