/** * X API v2 Client - Official Twitter/X API v2 implementation * Supports both App-Only (Bearer Token) and User Context (OAuth 1.0a) authentication */ export interface XApiV2ClientOptions { bearerToken?: string; apiKey?: string; apiSecret?: string; accessToken?: string; accessTokenSecret?: string; timeoutMs?: number; } export interface Tweet { id: string; text: string; author_id?: string; created_at?: string; conversation_id?: string; in_reply_to_user_id?: string; referenced_tweets?: Array<{ type: 'replied_to' | 'quoted' | 'retweeted'; id: string; }>; public_metrics?: { retweet_count: number; reply_count: number; like_count: number; quote_count: number; bookmark_count?: number; impression_count?: number; }; attachments?: { media_keys?: string[]; poll_ids?: string[]; }; entities?: { urls?: Array<{ start: number; end: number; url: string; expanded_url: string; display_url: string; }>; mentions?: Array<{ start: number; end: number; username: string; id: string; }>; hashtags?: Array<{ start: number; end: number; tag: string; }>; }; } export interface User { id: string; name: string; username: string; description?: string; profile_image_url?: string; created_at?: string; public_metrics?: { followers_count: number; following_count: number; tweet_count: number; listed_count: number; }; verified?: boolean; verified_type?: string; } export interface Media { media_key: string; type: 'photo' | 'video' | 'animated_gif'; url?: string; preview_image_url?: string; width?: number; height?: number; alt_text?: string; } export interface ApiResponse { data?: T; includes?: { users?: User[]; tweets?: Tweet[]; media?: Media[]; }; meta?: { result_count?: number; newest_id?: string; oldest_id?: string; next_token?: string; previous_token?: string; }; errors?: Array<{ title: string; detail: string; type: string; status?: number; }>; } export interface SearchResult { success: boolean; tweets?: TweetData[]; nextCursor?: string; error?: string; } export interface TweetData { id: string; text: string; author: { username: string; name: string; }; authorId?: string; createdAt?: string; replyCount?: number; retweetCount?: number; likeCount?: number; quoteCount?: number; conversationId?: string; inReplyToStatusId?: string; quotedTweet?: TweetData; media?: Array<{ type: string; url?: string; previewUrl?: string; altText?: string; }>; } export interface GetTweetResult { success: boolean; tweet?: TweetData; error?: string; } export interface UserResult { success: boolean; user?: UserData; error?: string; } export interface UserData { id: string; username: string; name: string; description?: string; followersCount?: number; followingCount?: number; tweetCount?: number; profileImageUrl?: string; createdAt?: string; verified?: boolean; } export interface PostTweetResult { success: boolean; tweet?: { id: string; text: string; }; error?: string; } export interface MutationResult { success: boolean; error?: string; } export declare class XApiV2Client { private bearerToken?; private oauth?; private accessToken?; private timeoutMs?; private cachedUserId?; constructor(options: XApiV2ClientOptions); private hasUserContext; private getAuthHeaders; private fetchWithTimeout; private request; private transformTweet; private hasCriticalError; private getErrorMessage; private transformUser; /** * Search recent tweets (last 7 days) */ searchRecentTweets(query: string, options?: { maxResults?: number; nextToken?: string; }): Promise; /** * Get a single tweet by ID */ getTweet(tweetId: string): Promise; /** * Get multiple tweets by IDs (up to 100) */ getTweets(tweetIds: string[]): Promise<{ success: boolean; tweets?: TweetData[]; error?: string; }>; /** * Get user by username */ getUserByUsername(username: string): Promise; /** * Get user by ID */ getUserById(userId: string): Promise; /** * Get current authenticated user (requires User Context) */ getMe(): Promise; /** * Get user's tweets (timeline) */ getUserTweets(userId: string, options?: { maxResults?: number; nextToken?: string; excludeReplies?: boolean; excludeRetweets?: boolean; }): Promise; /** * Get tweets mentioning a user (requires User Context for own mentions) */ getUserMentions(userId: string, options?: { maxResults?: number; nextToken?: string; }): Promise; /** * Get user's followers */ getFollowers(userId: string, options?: { maxResults?: number; nextToken?: string; }): Promise<{ success: boolean; users?: UserData[]; nextCursor?: string; error?: string; }>; /** * Get users that a user is following */ getFollowing(userId: string, options?: { maxResults?: number; nextToken?: string; }): Promise<{ success: boolean; users?: UserData[]; nextCursor?: string; error?: string; }>; /** * Get tweets from a list */ getListTweets(listId: string, options?: { maxResults?: number; nextToken?: string; }): Promise; /** * Get reverse chronological home timeline (requires User Context) */ getHomeTimeline(options?: { maxResults?: number; nextToken?: string; }): Promise; /** * Get user's liked tweets (requires User Context) */ getLikedTweets(userId: string, options?: { maxResults?: number; nextToken?: string; }): Promise; /** * Get user's bookmarks (requires User Context) */ getBookmarks(options?: { maxResults?: number; nextToken?: string; }): Promise; /** * Post a new tweet */ postTweet(text: string, options?: { replyTo?: string; quoteTweetId?: string; }): Promise; /** * Delete a tweet */ deleteTweet(tweetId: string): Promise; /** * Like a tweet */ likeTweet(tweetId: string): Promise; /** * Unlike a tweet */ unlikeTweet(tweetId: string): Promise; /** * Retweet a tweet */ retweet(tweetId: string): Promise; /** * Remove a retweet */ unretweet(tweetId: string): Promise; /** * Bookmark a tweet */ bookmark(tweetId: string): Promise; /** * Remove a bookmark */ unbookmark(tweetId: string): Promise; /** * Follow a user */ follow(targetUserId: string): Promise; /** * Unfollow a user */ unfollow(targetUserId: string): Promise; } /** * Resolve credentials from environment */ export declare function resolveCredentials(): { bearerToken?: string; apiKey?: string; apiSecret?: string; accessToken?: string; accessTokenSecret?: string; }; //# sourceMappingURL=x-api-v2-client.d.ts.map