### Rettiwt API Command-Line Interface (CLI) Usage (Bash) Source: https://context7.com/rishikant181/rettiwt-api/llms.txt Provides examples of using the Rettiwt API from the command line without writing code. Covers installation, setting API keys, getting help, and performing various Twitter operations like fetching user/tweet details, searching, posting, and managing likes/retweets. Dependencies include 'npm'. ```bash # Install globally npm install -g rettiwt-api # Set API key as environment variable export API_KEY="your_api_key_here" # Or pass API key with each command rettiwt -k "your_api_key" # Get help rettiwt help rettiwt help tweet rettiwt help user # Fetch user details rettiwt user details elonmusk # Fetch tweet details rettiwt tweet details 1234567890 # Fetch multiple tweets rettiwt tweet details 1234567890,0987654321,1122334455 # Search tweets rettiwt tweet search --from elonmusk --words "AI,technology" 10 # Search with filters rettiwt tweet search \ --from user1,user2 \ --words bitcoin,crypto \ --min-likes 100 \ --start "2024-01-01" \ --end "2024-12-31" \ --only-original \ 20 # Stream tweets in real-time rettiwt tweet search --from elonmusk --stream --interval 30000 # Post a tweet rettiwt tweet post "Hello from CLI!" # Post with media rettiwt tweet upload ./image.jpg # Returns media ID rettiwt tweet post "Check this out!" --media media_id_here # Like/unlike tweets rettiwt tweet like 1234567890 rettiwt tweet unlike 1234567890 # Retweet/unretweet rettiwt tweet retweet 1234567890 rettiwt tweet unretweet 1234567890 # Bookmark management rettiwt tweet bookmark 1234567890 rettiwt tweet unbookmark 1234567890 # Get user timeline rettiwt user timeline 1234567890 20 # Get followers rettiwt user followers 1234567890 100 # Search users rettiwt user search "elon" 10 # Follow/unfollow rettiwt user follow 1234567890 rettiwt user unfollow 1234567890 # List operations rettiwt list details 1234567890 rettiwt list tweets 1234567890 50 rettiwt list members 1234567890 100 # Space details rettiwt space details 1YqJDNEzvoVKV # DM operations rettiwt dm inbox rettiwt dm conversation conversation_id # With proxy and logging rettiwt -k "api_key" -p "http://proxy:8080" -l tweet details 1234567890 ``` -------------------------------- ### Install Rettiwt-API as a dependency Source: https://github.com/rishikant181/rettiwt-api/blob/dev/README.md Instructions for installing the Rettiwt-API library as a local dependency in a NodeJS project using either npm or yarn. ```bash npm install --save rettiwt-api ``` ```bash yarn add rettiwt-api ``` -------------------------------- ### Manage Following and Followers (TypeScript) Source: https://context7.com/rishikant181/rettiwt-api/llms.txt Provides examples for managing follow relationships and fetching follower/following lists using the Rettiwt API. Includes functions to follow, unfollow, get followers, get following, and get affiliates. Requires the 'rettiwt-api' package and an API key. ```typescript import { Rettiwt } from 'rettiwt-api'; const rettiwt = new Rettiwt({ apiKey: 'YOUR_API_KEY' }); const userId = '1234567890'; // Follow a user rettiwt.user.follow(userId) .then(success => console.log(`Followed: ${success}`)) .catch(err => console.error(err)); // Unfollow a user rettiwt.user.unfollow(userId) .then(success => console.log(`Unfollowed: ${success}`)) .catch(err => console.error(err)); // Get followers of a user rettiwt.user.followers(userId, 100) .then(data => { console.log(`Followers: ${data.list.length}`); data.list.forEach(user => console.log(`@${user.userName}`)); }) .catch(err => console.error(err)); // Get users that a user is following rettiwt.user.following(userId, 100) .then(data => { console.log(`Following: ${data.list.length}`); data.list.forEach(user => console.log(`@${user.userName}`)); }) .catch(err => console.error(err)); // Get your own followers (no ID needed) rettiwt.user.followers() .then(data => console.log(`You have ${data.list.length} followers`)) .catch(err => console.error(err)); // Get affiliates of a user rettiwt.user.affiliates(userId, 100) .then(data => { data.list.forEach(user => console.log(`Affiliate: @${user.userName}`)); }) .catch(err => console.error(err)); // Get user subscriptions rettiwt.user.subscriptions(userId, 100) .then(data => { data.list.forEach(user => console.log(`Subscribed to: @${user.userName}`)); }) .catch(err => console.error(err)); ``` -------------------------------- ### Get Twitter user details using Rettiwt Source: https://github.com/rishikant181/rettiwt-api/blob/dev/README.md Shows how to fetch the details of a specific Twitter user by providing their username to the `user.details()` method. This example uses 'guest' authentication. ```javascript import { Rettiwt } from 'rettiwt-api'; // Creating a new Rettiwt instance // Note that for accessing user details, 'guest' authentication can be used const rettiwt = new Rettiwt(); // Fetching the details of the user whose username is rettiwt.user.details('') .then(details => { // Process details }) .catch(error => { // Handle error }); ``` -------------------------------- ### Change Rettiwt API key dynamically Source: https://github.com/rishikant181/rettiwt-api/blob/dev/README.md Example of how to dynamically change the API key of an existing Rettiwt instance and then use it to fetch user details. This showcases the hot-swappable nature of the apiKey property. ```typescript import { Rettiwt } from 'rettiwt-api'; // Initializing a new Rettiwt instance with API key 1 const rettiwt = new Rettiwt({ apiKey: '' }); rettiwt.user.details().then((res) => { console.log(res); // Returns details of the user associated with API_KEY_1 }); // Changing API key to API key 2 rettiwt.apiKey = ''; rettiwt.user.details().then((res) => { console.log(res); // Returns details of the user associated with API_KEY_2 }); ``` -------------------------------- ### Fetch Tweet Replies with Sorting and Pagination (TypeScript) Source: https://context7.com/rishikant181/rettiwt-api/llms.txt Demonstrates how to fetch replies to a specific tweet using the Rettiwt API. Supports sorting by likes or relevance and includes an example of paginating through all replies. Requires the 'rettiwt-api' package and an API key. ```typescript import { Rettiwt, TweetRepliesSortType } from 'rettiwt-api'; const rettiwt = new Rettiwt({ apiKey: 'YOUR_API_KEY' }); // Get latest replies (default) rettiwt.tweet.replies('1234567890123456789') .then(data => { console.log(`Found ${data.list.length} replies`); data.list.forEach(reply => { console.log(`@${reply.tweetBy.userName}: ${reply.fullText}`); }); }) .catch(err => console.error(err)); // Get replies sorted by likes rettiwt.tweet.replies('1234567890', undefined, TweetRepliesSortType.LIKES) .then(data => console.log(data)) .catch(err => console.error(err)); // Get replies sorted by relevance rettiwt.tweet.replies('1234567890', undefined, TweetRepliesSortType.RELEVANCE) .then(data => console.log(data)) .catch(err => console.error(err)); // Paginate through all replies async function getAllReplies(tweetId: string) { const allReplies = []; let cursor = undefined; while (true) { const data = await rettiwt.tweet.replies(tweetId, cursor); allReplies.push(...data.list); if (!data.next) break; cursor = data.next; } return allReplies; } ``` -------------------------------- ### Direct Raw Response Access with Rettiwt FetcherService Source: https://github.com/rishikant181/rettiwt-api/blob/dev/README.md Shows how to use the FetcherService from Rettiwt-API to get direct access to the raw Twitter API response. This approach requires manual parsing and filtering of the results by the consumer. ```typescript import { RettiwtConfig, FetcherService, ResourceType, IUserDetailsResponse } from 'rettiwt-api'; // Creating the configuration for Rettiwt const config = new RettiwtConfig({ apiKey: '' }); // Creating a new FetcherService instance using the config const fetcher = new FetcherService(config); // Fetching the details of the given user fetcher .request(ResourceType.USER_DETAILS_BY_USERNAME, { id: 'user1' }) .then((res) => { console.log(res); // Raw response object }) .catch((err) => { console.log(err); }); ``` -------------------------------- ### GET /user/details Source: https://github.com/rishikant181/rettiwt-api/blob/dev/README.md Fetches the details of a target Twitter user. This operation can be performed using 'guest' authentication. ```APIDOC ## GET /user/details ### Description Retrieves the details of a specified Twitter user. This endpoint can be accessed using guest authentication. ### Method `GET` ### Endpoint `/user/details` ### Parameters #### Query Parameters - **username** (string) - Required - The username of the Twitter user whose details are to be fetched. ### Request Example ```javascript import { Rettiwt } from 'rettiwt-api'; // Creating a new Rettiwt instance (guest authentication) const rettiwt = new Rettiwt(); // Fetching the details of the user with username 'exampleUser' rettiwt.user.details('exampleUser') .then(details => { console.log(details); }) .catch(error => { console.error(error); }); ``` ### Response #### Success Response (200) - **userDetails** (object) - An object containing the details of the specified Twitter user. #### Response Example ```json { "id": "123456789", "name": "Example User", "username": "exampleUser", "description": "This is an example user description.", "profile_image_url": "https://example.com/profile.jpg", "followers_count": 1000, "following_count": 500 } ``` ``` -------------------------------- ### Get Raw User Details using Rettiwt API 'raw' getter Source: https://github.com/rishikant181/rettiwt-api/blob/dev/README.md Demonstrates how to fetch user details using the Rettiwt API and access the original, unparsed Twitter response via the 'raw' getter. This method is useful when you need the exact data structure returned by Twitter. ```typescript import { Rettiwt } from 'rettiwt-api'; // Creating a new Rettiwt instance // Note that for accessing user details, 'guest' authentication can be used const rettiwt = new Rettiwt(); // Fetching the details of the user whose username is rettiwt.user.details('') .then(details => { console.log(details); // Rettiwt's parsed data entity console.log(details.raw); // Raw Twitter API response }) .catch(error => { // Handle errors }); ``` -------------------------------- ### Schedule Tweets with Rettiwt API (TypeScript) Source: https://context7.com/rishikant181/rettiwt-api/llms.txt This snippet shows how to schedule tweets for future posting using the Rettiwt API. It includes examples for scheduling a simple tweet, a tweet with media, and canceling a scheduled tweet. Requires the 'rettiwt-api' package and an API key. ```typescript import { Rettiwt } from 'rettiwt-api'; const rettiwt = new Rettiwt({ apiKey: 'YOUR_API_KEY' }); // Schedule a tweet for tomorrow at noon const tomorrow = new Date(); tomorrow.setDate(tomorrow.getDate() + 1); tomorrow.setHours(12, 0, 0, 0); rettiwt.tweet.schedule({ text: 'This tweet was scheduled in advance!', scheduleFor: tomorrow }) .then(scheduleId => console.log(`Scheduled tweet ID: ${scheduleId}`)) .catch(err => console.error(err)); // Schedule a tweet with media async function scheduleMediaTweet() { const mediaId = await rettiwt.tweet.upload('./promo-image.png'); const scheduleId = await rettiwt.tweet.schedule({ text: 'Coming soon! Stay tuned for our big announcement.', media: [{ id: mediaId }], scheduleFor: new Date('2024-12-25 09:00:00') }); console.log(`Scheduled: ${scheduleId}`); } // Cancel a scheduled tweet rettiwt.tweet.unschedule('scheduled_tweet_id') .then(success => console.log(`Unscheduled: ${success}`)) .catch(err => console.error(err)); ``` -------------------------------- ### Manage Twitter Lists with Rettiwt API (TypeScript) Source: https://context7.com/rishikant181/rettiwt-api/llms.txt This code demonstrates how to manage Twitter lists using the Rettiwt API. It covers fetching list details, retrieving tweets from a list, managing list members (adding and removing), and getting all lists associated with the logged-in user. An API key is required for authentication. ```typescript import { Rettiwt } from 'rettiwt-api'; const rettiwt = new Rettiwt({ apiKey: 'YOUR_API_KEY' }); const listId = '1234567890'; // Get list details rettiwt.list.details(listId) .then(list => { console.log(`List: ${list?.name}`); console.log(`Description: ${list?.description}`); console.log(`Members: ${list?.memberCount}`); console.log(`Followers: ${list?.followerCount}`); }) .catch(err => console.error(err)); // Get tweets from a list rettiwt.list.tweets(listId, 100) .then(data => { console.log(`${data.list.length} tweets from list`); data.list.forEach(tweet => console.log(tweet.fullText)); }) .catch(err => console.error(err)); // Get list members rettiwt.list.members(listId, 100) .then(data => { console.log(`List has ${data.list.length} members`); data.list.forEach(user => console.log(`@${user.userName}`)); }) .catch(err => console.error(err)); // Add a member to your list rettiwt.list.addMember(listId, 'user_id_to_add') .then(newMemberCount => console.log(`New member count: ${newMemberCount}`)) .catch(err => console.error(err)); // Remove a member from your list rettiwt.list.removeMember(listId, 'user_id_to_remove') .then(newMemberCount => console.log(`New member count: ${newMemberCount}`)) .catch(err => console.error(err)); // Get all lists for the logged-in user rettiwt.user.lists(100) .then(data => { data.list.forEach(list => console.log(`${list.name}: ${list.memberCount} members`)); }) .catch(err => console.error(err)); ``` -------------------------------- ### Initialize Rettiwt instance for authentication Source: https://github.com/rishikant181/rettiwt-api/blob/dev/README.md Demonstrates how to create a new Rettiwt instance for either 'guest' authentication (no API key required) or 'user' authentication using a provided API key. ```javascript const rettiwt = new Rettiwt() // for 'guest' authentication const rettiwt = new Rettiwt({ apiKey: API_KEY }) // for 'user' authentication ``` -------------------------------- ### Rettiwt Class Initialization Source: https://github.com/rishikant181/rettiwt-api/blob/dev/README.md Demonstrates how to initialize a new Rettiwt instance for both guest and user authentication. ```APIDOC ## Rettiwt Class Initialization ### Description Initialize a new Rettiwt instance for interacting with the Twitter API. Supports both 'guest' authentication (no API key required) and 'user' authentication using an API key. ### Method `new Rettiwt([options])` ### Parameters #### Options Object - **apiKey** (string) - Optional - The API key for 'user' authentication. If not provided, 'guest' authentication is used. ### Request Example ```javascript // For 'guest' authentication const rettiwtGuest = new Rettiwt(); // For 'user' authentication const rettiwtUser = new Rettiwt({ apiKey: 'YOUR_API_KEY' }); ``` ### Response Returns a new Rettiwt instance. #### Success Response - **rettiwtInstance** (object) - An initialized Rettiwt object. #### Response Example ```javascript // Example of a successful initialization const rettiwt = new Rettiwt({ apiKey: 'YOUR_API_KEY' }); console.log(rettiwt); // Rettiwt instance ``` ``` -------------------------------- ### CLI Usage Source: https://github.com/rishikant181/rettiwt-api/blob/dev/README.md Information on how to use the Rettiwt API via its command-line interface. ```APIDOC ## CLI Usage ### Description Provides instructions for using the Rettiwt API's command-line interface (CLI), including authentication methods. ### Authentication - **Default**: The CLI operates in 'guest' authentication mode by default. - **User Authentication**: 1. Generate an `API_KEY` as described in the [Authentication](https://rishikant181.github.io/Rettiwt-API/#md:authentication) section. 2. Store the generated `API_KEY` as an environment variable named `API_KEY`. 3. The CLI will automatically use this environment variable for authentication. 4. Alternatively, the `API_KEY` can be passed manually using the `-k` option: `rettiwt -k `. ### Help Commands - **General Help**: `rettiwt help` - Displays help for available commands. - **Specific Command Help**: `rettiwt help ` - Displays help for a particular command. ``` -------------------------------- ### Initialize Rettiwt API Client Source: https://context7.com/rishikant181/rettiwt-api/llms.txt Demonstrates how to initialize the Rettiwt client with different authentication methods and configuration options. Supports guest authentication for public data and user authentication using an API key derived from browser cookies for full access. Advanced configurations include proxy, timeout, logging, and retry settings. ```typescript import { Rettiwt } from 'rettiwt-api'; // Guest authentication (limited access - tweet details, user details, timelines) const guestRettiwt = new Rettiwt(); // User authentication (full access - requires API_KEY from browser cookies) const rettiwt = new Rettiwt({ apiKey: 'YOUR_API_KEY' }); // Full configuration with proxy, timeout, logging, and retry settings const rettiwtFull = new Rettiwt({ apiKey: 'YOUR_API_KEY', proxyUrl: new URL('http://proxy.example.com:8080'), timeout: 30000, logging: true, maxRetries: 5, delay: 1000, // Delay between requests in ms headers: { 'Custom-Header': 'value' } }); // Hot-swap API key at runtime rettiwt.apiKey = 'NEW_API_KEY'; rettiwt.proxyUrl = new URL('http://new-proxy.example.com:8080'); ``` -------------------------------- ### Rettiwt Configuration Options Source: https://github.com/rishikant181/rettiwt-api/blob/dev/README.md Details on the configuration parameters available when initializing a Rettiwt instance, including hot-swappable options. ```APIDOC ## Rettiwt Configuration Options ### Description When initializing a new Rettiwt instance, you can configure its behavior using various parameters. ### Parameters - **apiKey** (string) - The API key to use for `user` authentication. - **proxyUrl** (URL) - The URL to the proxy server to use. - **timeout** (number) - The timeout to use for HTTP requests (in milliseconds). - **logging** (boolean) - Whether to enable logging. - **errorHandler** (interface) - A custom error handler function. - **tidProvider** (interface) - A custom TID provider for generating transaction tokens. - **headers** (object) - Custom HTTP headers to append to the default headers. - **delay** (number/function) - Delay in milliseconds between concurrent requests. Can be a number or a function returning a number. Defaults to 0. - **maxRetries** (number) - Maximum retries for encountering a random 404 error. Defaults to 0. ### Hot-Swappable Parameters The following parameters can be changed on the fly after initialization: - `apiKey` - `headers` - `proxyUrl` ### Usage Example (Changing API Key) ```javascript import { Rettiwt } from 'rettiwt-api'; // Initializing with API key 1 const rettiwt = new Rettiwt({ apiKey: '' }); // Fetching user details with API key 1 rettiwt.user.details().then(res => { console.log('Details with API_KEY_1:', res); }); // Changing API key to API key 2 rettiwt.apiKey = ''; // Fetching user details with API key 2 rettiwt.user.details().then(res => { console.log('Details with API_KEY_2:', res); }); ``` ``` -------------------------------- ### Generate API Key with User Authentication Source: https://github.com/rishikant181/rettiwt-api/blob/dev/README.md Demonstrates how to obtain an API key dynamically at runtime by logging in with user credentials (email, username, password). This is useful for implementing features like Twitter login within an application. The API key is returned via a promise. ```typescript import { Rettiwt } from 'rettiwt-api'; // Creating a new Rettiwt instance const rettiwt = new Rettiwt(); // Logging in an getting the API_KEY rettiwt.auth.login('', '', '') .then(apiKey => { // Use the API_KEY // ... }) .catch(err => { console.log(err); }); ``` -------------------------------- ### Enable Debug Logging Source: https://github.com/rishikant181/rettiwt-api/blob/dev/README.md Enables debug logging for troubleshooting by setting the 'logging' property to true during Rettiwt instance initialization. Debug logs are printed to the console, aiding in tracking down unexpected behavior. ```typescript /** * By default, is no value for 'logging' is supplied, logging is disabled. */ const rettiwt = new Rettiwt({ apiKey: API_KEY, logging: true }); ``` -------------------------------- ### Configure Proxy Server Source: https://github.com/rishikant181/rettiwt-api/blob/dev/README.md Configures the Rettiwt instance to use a specified proxy server for making requests. This is useful for masking IP addresses. The proxy URL is provided during the Rettiwt instance creation. ```typescript /** * PROXY_URL is the URL or configuration for the proxy server you want to use.` */ const rettiwt = new Rettiwt({ apiKey: API_KEY, proxyUrl: PROXY_URL }); ``` -------------------------------- ### Access Raw Twitter API Responses with FetcherService (TypeScript) Source: https://context7.com/rishikant181/rettiwt-api/llms.txt Demonstrates how to use FetcherService to access raw Twitter API responses for advanced use cases. It covers fetching user details and hot-swapping configuration. Dependencies include 'rettiwt-api'. ```typescript import { RettiwtConfig, FetcherService, ResourceType } from 'rettiwt-api'; // Create configuration const config = new RettiwtConfig({ apiKey: 'YOUR_API_KEY' }); // Create FetcherService for raw access const fetcher = new FetcherService(config); // Fetch raw user details fetcher.request(ResourceType.USER_DETAILS_BY_USERNAME, { id: 'elonmusk' }) .then(response => { console.log('Raw Twitter response:', JSON.stringify(response, null, 2)); }) .catch(err => console.error(err)); // Hot-swap configuration config.apiKey = 'NEW_API_KEY'; config.proxyUrl = new URL('http://new-proxy.example.com'); // Access raw data from standard responses import { Rettiwt } from 'rettiwt-api'; const rettiwt = new Rettiwt({ apiKey: 'YOUR_API_KEY' }); rettiwt.user.details('elonmusk') .then(user => { // Parsed, typed response console.log('Parsed:', user.fullName); // Raw Twitter response console.log('Raw:', user.raw); }) .catch(err => console.error(err)); ``` -------------------------------- ### Implement Custom Error Handler Source: https://github.com/rishikant181/rettiwt-api/blob/dev/README.md Shows how to create and use a custom error handler by implementing the `IErrorHandler` interface. This allows for more advanced error diagnosis by providing access to the raw error response from Twitter, bypassing the default Rettiwt error handling. ```typescript import { Rettiwt, IErrorHandler } from 'rettiwt-api'; // Implementing an error handler class CustomErrorHandler implements IErrorHandler { /** * This is where you handle the error yourself. */ public handler(error: unknown): void { // The 'error' variable has the full, raw error response returned from Twitter. /** * You custom error handling logic goes here */ console.log(`Raw Twitter Error: ${JSON.stringify(error)}`); } } // Now we'll use the implemented error handler while initializing Rettiwt const rettiwt = new Rettiwt({ apiKey: '', errorHandler: CustomErrorHandler }); ``` -------------------------------- ### Fetch User Timeline, Replies, and Media (TypeScript) Source: https://context7.com/rishikant181/rettiwt-api/llms.txt Shows how to retrieve a user's tweet timeline, replies, and media posts using the Rettiwt API. It demonstrates fetching a specified number of tweets and handling pagination. Requires the 'rettiwt-api' package and an API key. ```typescript import { Rettiwt } from 'rettiwt-api'; const rettiwt = new Rettiwt({ apiKey: 'YOUR_API_KEY' }); const userId = '1234567890'; // Get user's tweet timeline (20 tweets max per request) rettiwt.user.timeline(userId, 20) .then(data => { console.log(`Timeline: ${data.list.length} tweets`); data.list.forEach(tweet => console.log(tweet.fullText)); console.log(`Next cursor: ${data.next}`); }) .catch(err => console.error(err)); // Get user's replies timeline rettiwt.user.replies(userId, 20) .then(data => { data.list.forEach(tweet => console.log(`Reply: ${tweet.fullText}`)); }) .catch(err => console.error(err)); // Get user's media timeline rettiwt.user.media(userId, 100) .then(data => { data.list.forEach(tweet => { console.log(`Media tweet: ${tweet.fullText}`); tweet.media?.forEach(m => console.log(` Media: ${m.url}`)); }); }) .catch(err => console.error(err)); // Get user's highlighted tweets rettiwt.user.highlights(userId, 100) .then(data => { data.list.forEach(tweet => console.log(`Highlight: ${tweet.fullText}`)); }) .catch(err => console.error(err)); // Get logged-in user's own timeline (no ID needed) rettiwt.user.timeline() .then(data => console.log(data)) .catch(err => console.error(err)); ``` -------------------------------- ### Fetch Twitter Spaces Details with Rettiwt API (TypeScript) Source: https://context7.com/rishikant181/rettiwt-api/llms.txt This snippet shows how to retrieve details about Twitter Spaces using the Rettiwt API. It includes fetching basic space information and an extended version with listener and replay data. An API key is required for authentication. ```typescript import { Rettiwt } from 'rettiwt-api'; const rettiwt = new Rettiwt({ apiKey: 'YOUR_API_KEY' }); // Get space details rettiwt.space.details('1YqJDNEzvoVKV') .then(space => { console.log(`Space: ${space?.title}`); console.log(`State: ${space?.state}`); console.log(`Host: ${space?.hostIds}`); console.log(`Participants: ${space?.participantCount}`); }) .catch(err => console.error(err)); // Get space details with listeners and replay info rettiwt.space.details('1YqJDNEzvoVKV', { withListeners: true, withReplays: true, isMetatagsQuery: false }) .then(space => console.log(space)) .catch(err => console.error(err)); ``` -------------------------------- ### Fetch User Details with Rettiwt API Source: https://context7.com/rishikant181/rettiwt-api/llms.txt Shows how to retrieve user details using the Rettiwt API by username or ID. Supports fetching single users, multiple users in bulk, and the details of the currently logged-in user. The function returns user object containing properties like ID, name, username, follower counts, verification status, and creation date. ```typescript import { Rettiwt } from 'rettiwt-api'; const rettiwt = new Rettiwt({ apiKey: 'YOUR_API_KEY' }); // Fetch user by username (works with or without @) rettiwt.user.details('elonmusk') .then(user => { console.log(`ID: ${user.id}`); console.log(`Name: ${user.fullName}`); console.log(`Username: ${user.userName}`); console.log(`Followers: ${user.followersCount}`); console.log(`Following: ${user.followingsCount}`); console.log(`Verified: ${user.isVerified}`); console.log(`Created: ${user.createdAt}`); }) .catch(err => console.error(err)); // Fetch user by ID rettiwt.user.details('1234567890') .then(user => console.log(user)) .catch(err => console.error(err)); // Fetch multiple users in bulk by IDs rettiwt.user.details(['44196397', '12345678', '87654321']) .then(users => { users.forEach(user => console.log(`${user.userName}: ${user.followersCount} followers`)); }) .catch(err => console.error(err)); // Fetch logged-in user's own details (no ID required) rettiwt.user.details() .then(user => console.log(`Logged in as: ${user.userName}`)) .catch(err => console.error(err)); ``` -------------------------------- ### User Service API Endpoints Source: https://github.com/rishikant181/rettiwt-api/blob/dev/README.md This section details various endpoints related to user data and interactions within the Rettiwt API. ```APIDOC ## UserService API Endpoints ### Description Provides access to various user-related data and actions, including profiles, followers, following, bookmarks, and more. ### Endpoints #### Get Affiliated Users - **Method**: GET (Assumed) - **Endpoint**: /users/affiliates - **Description**: Retrieves a list of users affiliated with a given user. #### Get User Analytics - **Method**: GET (Assumed) - **Endpoint**: /users/analytics - **Description**: Retrieves analytics for the logged-in user (premium accounts only). #### Get User About Profile - **Method**: GET (Assumed) - **Endpoint**: /users/{userId}/about - **Description**: Retrieves the 'about' profile information for a specific user. #### Get Bookmarked Tweets - **Method**: GET (Assumed) - **Endpoint**: /users/me/bookmarks - **Description**: Retrieves a list of tweets bookmarked by the logged-in user. #### Get Bookmark Folders - **Method**: GET (Assumed) - **Endpoint**: /users/me/bookmark-folders - **Description**: Retrieves a list of bookmark folders belonging to the logged-in user. #### Get Tweets in Bookmark Folder - **Method**: GET (Assumed) - **Endpoint**: /users/me/bookmark-folders/{folderId}/tweets - **Description**: Retrieves tweets within a specific bookmark folder. #### Get User Details - **Method**: GET (Assumed) - **Endpoint**: /users/details - **Description**: Retrieves detailed information for one or more users. - **Query Parameters**: - **userIds** (string) - Required - Comma-separated list of user IDs. #### Follow User - **Method**: POST (Assumed) - **Endpoint**: /users/{userId}/follow - **Description**: Follows a specified user. #### Get Followed Feed - **Method**: GET (Assumed) - **Endpoint**: /users/me/followed-feed - **Description**: Retrieves the followed feed of the logged-in user. #### Get Followers - **Method**: GET (Assumed) - **Endpoint**: /users/{userId}/followers - **Description**: Retrieves the list of users who follow a given user. #### Get Following - **Method**: GET (Assumed) - **Endpoint**: /users/{userId}/following - **Description**: Retrieves the list of users whom a given user is following. #### Get Highlighted Tweets - **Method**: GET (Assumed) - **Endpoint**: /users/{userId}/highlights - **Description**: Retrieves the highlighted tweets of a given user. #### Get Liked Tweets - **Method**: GET (Assumed) - **Endpoint**: /users/me/likes - **Description**: Retrieves a list of tweets liked by the logged-in user. #### Get User Lists - **Method**: GET (Assumed) - **Endpoint**: /users/me/lists - **Description**: Retrieves the lists created by the logged-in user. #### Get User Media Timeline - **Method**: GET (Assumed) - **Endpoint**: /users/{userId}/media - **Description**: Retrieves the media timeline of a given user. #### Stream User Notifications - **Method**: GET (Assumed) - **Endpoint**: /users/me/notifications/stream - **Description**: Streams notifications for the logged-in user in pseudo-realtime. #### Get Recommended Feed - **Method**: GET (Assumed) - **Endpoint**: /users/me/recommended-feed - **Description**: Retrieves the recommended feed for the logged-in user. #### Get User Replies Timeline - **Method**: GET (Assumed) - **Endpoint**: /users/{userId}/replies - **Description**: Retrieves the replies timeline of a given user. #### Search Username - **Method**: GET (Assumed) - **Endpoint**: /users/search - **Description**: Searches for a username. - **Query Parameters**: - **query** (string) - Required - The username to search for. #### Get User Timeline - **Method**: GET (Assumed) - **Endpoint**: /users/{userId}/timeline - **Description**: Retrieves the tweet timeline of a given user. #### Unfollow User - **Method**: POST (Assumed) - **Endpoint**: /users/{userId}/unfollow - **Description**: Unfollows a specified user. #### Update User Profile - **Method**: PUT (Assumed) - **Endpoint**: /users/me/profile - **Description**: Updates the profile of the logged-in user. - **Request Body**: - **field** (object) - Required - Profile fields to update. ``` -------------------------------- ### Search Users with Rettiwt API Source: https://context7.com/rishikant181/rettiwt-api/llms.txt Searches for users based on a username query. It supports fetching a specified number of results and paginating through them. Requires an API key for initialization. ```typescript import { Rettiwt } from 'rettiwt-api'; const rettiwt = new Rettiwt({ apiKey: 'YOUR_API_KEY' }); // Search for users matching a username rettiwt.user.search('elonmusk', 20) .then(data => { console.log(`Found ${data.list.length} users`); data.list.forEach(user => { console.log(`@${user.userName} - ${user.fullName} (${user.followersCount} followers)`); }); }) .catch(err => console.error(err)); // Paginate through search results async function searchAllUsers(query: string, maxResults = 100) { const allUsers = []; let cursor = undefined; while (allUsers.length < maxResults) { const data = await rettiwt.user.search(query, 20, cursor); allUsers.push(...data.list); if (!data.next || data.list.length === 0) break; cursor = data.next; } return allUsers; } ``` -------------------------------- ### Post and Manage Tweets with Rettiwt API (TypeScript) Source: https://context7.com/rishikant181/rettiwt-api/llms.txt This snippet demonstrates how to post simple text tweets, reply to existing tweets, quote tweets, and upload media for inclusion in tweets using the Rettiwt API. It also covers deleting tweets. Requires the 'rettiwt-api' package and an API key. ```typescript import { Rettiwt } from 'rettiwt-api'; const rettiwt = new Rettiwt({ apiKey: 'YOUR_API_KEY' }); // Post a simple text tweet rettiwt.tweet.post({ text: 'Hello Twitter from Rettiwt-API!' }) .then(tweetId => console.log(`Posted tweet: ${tweetId}`)) .catch(err => console.error(err)); // Reply to a tweet rettiwt.tweet.post({ text: 'This is a reply!', replyTo: '1234567890123456789' }) .then(tweetId => console.log(`Reply posted: ${tweetId}`)) .catch(err => console.error(err)); // Quote a tweet rettiwt.tweet.post({ text: 'Interesting take! Here are my thoughts:', quote: '1234567890123456789' }) .then(tweetId => console.log(`Quote tweet posted: ${tweetId}`)) .catch(err => console.error(err)); // Upload media and post tweet with image async function postTweetWithImage() { // First upload the media (valid for 24 hours) const mediaId = await rettiwt.tweet.upload('./image.jpg'); console.log(`Media uploaded: ${mediaId}`); // Then post tweet with the media const tweetId = await rettiwt.tweet.post({ text: 'Check out this amazing view!', media: [{ id: mediaId }] }); console.log(`Tweet with image posted: ${tweetId}`); } // Upload media from ArrayBuffer async function uploadFromBuffer(buffer: ArrayBuffer) { const mediaId = await rettiwt.tweet.upload(buffer); return mediaId; } // Post tweet with multiple images and tag users rettiwt.tweet.post({ text: 'Great event with friends!', media: [ { id: 'media_id_1', tags: ['user_id_1', 'user_id_2'] }, { id: 'media_id_2', tags: ['user_id_3'] } ] }) .then(tweetId => console.log(`Posted: ${tweetId}`)) .catch(err => console.error(err)); // Delete (unpost) a tweet rettiwt.tweet.unpost('1234567890123456789') .then(success => console.log(`Tweet deleted: ${success}`)) .catch(err => console.error(err)); ``` -------------------------------- ### Search Tweets with Timeout and Retries (CLI) Source: https://context7.com/rishikant181/rettiwt-api/llms.txt This command demonstrates how to search for tweets from a specific user with a configured timeout and retry mechanism using the Rettiwt-API command-line interface. It specifies the API key, timeout duration, number of retries, and delay between retries. ```bash rettiwt -k "api_key" -t 30000 -r 5 -d 1000 tweet search --from elonmusk 20 ``` -------------------------------- ### Access Bookmarks and Liked Tweets with Rettiwt API Source: https://context7.com/rishikant181/rettiwt-api/llms.txt Fetches the authenticated user's bookmarked tweets, bookmark folders, and liked tweets. Supports retrieving tweets from specific bookmark folders. Requires an API key. ```typescript import { Rettiwt } from 'rettiwt-api'; const rettiwt = new Rettiwt({ apiKey: 'YOUR_API_KEY' }); // Get your bookmarked tweets rettiwt.user.bookmarks(100) .then(data => { console.log(`You have ${data.list.length} bookmarks`); data.list.forEach(tweet => console.log(tweet.fullText)); }) .catch(err => console.error(err)); // Get bookmark folders rettiwt.user.bookmarkFolders() .then(data => { data.list.forEach(folder => { console.log(`Folder: ${folder.name} (ID: ${folder.id})`); }); }) .catch(err => console.error(err)); // Get tweets from a specific bookmark folder rettiwt.user.bookmarkFolderTweets('folder_id', 100) .then(data => { data.list.forEach(tweet => console.log(tweet.fullText)); }) .catch(err => console.error(err)); // Get your liked tweets rettiwt.user.likes(100) .then(data => { console.log(`You have liked ${data.list.length} tweets`); data.list.forEach(tweet => console.log(tweet.fullText)); }) .catch(err => console.error(err)); ``` -------------------------------- ### Tweet Interactions with Rettiwt API (TypeScript) Source: https://context7.com/rishikant181/rettiwt-api/llms.txt This snippet demonstrates how to perform common tweet interactions like liking, retweeting, and bookmarking tweets using the Rettiwt API. It also shows how to un-like, un-retweet, remove bookmarks, and retrieve lists of users who liked or retweeted a tweet. Requires the 'rettiwt-api' package and an API key. ```typescript import { Rettiwt } from 'rettiwt-api'; const rettiwt = new Rettiwt({ apiKey: 'YOUR_API_KEY' }); const tweetId = '1234567890123456789'; // Like a tweet rettiwt.tweet.like(tweetId) .then(success => console.log(`Liked: ${success}`)) .catch(err => console.error(err)); // Unlike a tweet rettiwt.tweet.unlike(tweetId) .then(success => console.log(`Unliked: ${success}`)) .catch(err => console.error(err)); // Retweet rettiwt.tweet.retweet(tweetId) .then(success => console.log(`Retweeted: ${success}`)) .catch(err => console.error(err)); // Unretweet rettiwt.tweet.unretweet(tweetId) .then(success => console.log(`Unretweeted: ${success}`)) .catch(err => console.error(err)); // Bookmark a tweet rettiwt.tweet.bookmark(tweetId) .then(success => console.log(`Bookmarked: ${success}`)) .catch(err => console.error(err)); // Remove bookmark rettiwt.tweet.unbookmark(tweetId) .then(success => console.log(`Unbookmarked: ${success}`)) .catch(err => console.error(err)); // Get users who liked your tweet (only works for own tweets) rettiwt.tweet.likers(tweetId, 100) .then(data => { console.log(`${data.list.length} likers found`); data.list.forEach(user => console.log(`@${user.userName}`)); }) .catch(err => console.error(err)); // Get users who retweeted a tweet rettiwt.tweet.retweeters(tweetId, 100) .then(data => { data.list.forEach(user => console.log(`@${user.userName} retweeted`)); }) .catch(err => console.error(err)); ``` -------------------------------- ### Manage User Profiles and Analytics with Rettiwt API Source: https://context7.com/rishikant181/rettiwt-api/llms.txt Retrieves extended user profile information and analytics. Allows updating the authenticated user's profile. Analytics retrieval is limited to premium accounts and requires specifying date ranges and metrics. Requires an API key. ```typescript import { Rettiwt, RawAnalyticsGranularity, RawAnalyticsMetric } from 'rettiwt-api'; const rettiwt = new Rettiwt({ apiKey: 'YOUR_API_KEY' }); // Get extended about profile information rettiwt.user.about('elonmusk') .then(about => { console.log('About profile:', about); }) .catch(err => console.error(err)); // Update your own profile rettiwt.user.updateProfile({ name: 'New Display Name', description: 'Updated bio with Rettiwt-API', location: 'San Francisco, CA', url: 'https://example.com' }) .then(success => console.log(`Profile updated: ${success}`)) .catch(err => console.error(err)); // Get analytics (premium accounts only) rettiwt.user.analytics( new Date('2024-01-01'), // Start date new Date('2024-01-31'), // End date RawAnalyticsGranularity.DAILY, [RawAnalyticsMetric.FOLLOWERS, RawAnalyticsMetric.PROFILE_VISITS], true // Include verified followers ) .then(analytics => console.log('Analytics:', analytics)) .catch(err => console.error(err)); // Get default 7-day analytics rettiwt.user.analytics() .then(analytics => console.log(analytics)) .catch(err => console.error(err)); ```