### Nitter Native Installation (Bash) Source: https://context7.com/zedeus/nitter/llms.txt Guides users through installing Nitter directly on a server without Docker. This involves creating a dedicated user, cloning the repository, building the application using Nimble, configuring settings by copying and editing the example configuration file, and finally running the Nitter server. ```bash # Create nitter user and clone repository useradd -m nitter su nitter git clone https://github.com/zedeus/nitter cd nitter # Build application nimble build -d:danger --mm:refc nimble scss nimble md # Configure and run cp nitter.example.conf nitter.conf # Edit nitter.conf with your settings redis-server --daemonize yes ./nitter ``` -------------------------------- ### Configure and Run Nitter Source: https://github.com/zedeus/nitter/blob/master/README.md Copies the example configuration file to nitter.conf and then runs the compiled Nitter executable. The configuration file must be updated with hostname, port, HMAC key, HTTPS settings, and Redis information. ```bash cp nitter.example.conf nitter.conf ./nitter ``` -------------------------------- ### Enable and Start Nitter systemd Service Source: https://github.com/zedeus/nitter/blob/master/README.md Enables the Nitter systemd service to start on boot and immediately starts the service. This command assumes the systemd service file has already been placed in the appropriate systemd directory. ```bash systemctl enable --now nitter.service ``` -------------------------------- ### Enable and Start Nitter Service (Bash) Source: https://context7.com/zedeus/nitter/llms.txt Bash commands to manage the Nitter systemd service. Includes steps for copying the service file, enabling and starting the service, checking its status, and viewing logs. ```bash # Copy service file sudo cp nitter.service /etc/systemd/system/ # Enable and start sudo systemctl enable --now nitter.service # Check status sudo systemctl status nitter.service # View logs journalctl -u nitter.service --follow ``` -------------------------------- ### Build Nitter using Nimble Source: https://github.com/zedeus/nitter/blob/master/README.md Builds the Nitter application using the Nimble package manager. It requires Nim to be installed and configures the build with specific flags for danger and reference counting. It also compiles SCSS and Markdown files. ```bash nimble build -d:danger --mm:refc nimble scss nimble md ``` -------------------------------- ### Configure Nitter Reverse Proxy and Headers (Caddyfile) Source: https://github.com/zedeus/nitter/wiki/Caddy This Caddyfile snippet configures a Nitter instance. It sets up essential security headers like Strict-Transport-Security, Referrer-Policy, and Content-Security-Policy. It also configures a reverse proxy to forward requests to a local Nitter backend and includes an option to discard logs. ```caddyfile nitter.example.com { header { Strict-Transport-Security "max-age=63072000" Referrer-Policy no-referrer X-Permitted-Cross-Domain-Policies none X-Content-Type-Options nosniff Permissions-Policy "Permissions-Policy: accelerometer=(), ambient-light-sensor=(), autoplay=(self), battery=(), camera=(), cross-origin-isolated=(), display-capture=(), document-domain=(), encrypted-media=(), execution-while-not-rendered=(), execution-while-out-of-viewport=(), fullscreen=(self), geolocation=(), gyroscope=(), keyboard-map=(), magnetometer=(), microphone=(), midi=(), navigation-override=(), payment=(), picture-in-picture=(self), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(), usb=(), web-share=(), xr-spatial-tracking=()" header Content-Security-Policy "default-src 'none'; script-src 'self' 'unsafe-inline'; img-src 'self'; style-src 'self' 'unsafe-inline'; font-src 'self'; object-src 'none'; media-src 'self' blob:; worker-src 'self' blob:; base-uri 'self'; form-action 'self'; frame-ancestors 'self'; connect-src 'self' https://*.twimg.com; manifest-src 'self'" } reverse_proxy http://localhost:8080 { transport http { compression off } } # Optional: discard logs completely log { output discard } } ``` -------------------------------- ### Nginx Configuration for Nitter with SSL Source: https://github.com/zedeus/nitter/wiki/Nginx This configuration sets up Nginx to serve Nitter over SSL. It includes directives for SSL certificate, protocols, ciphers, and security headers. The configuration proxies requests to a Nitter instance running on a specified port. ```nginx server { listen 443 ssl; server_name YOUR_DOMAIN_NAME; ssl_certificate YOUR_SSL_CERT; ssl_certificate_key YOUR_SSL_CERT_KEY; ssl_protocols TLSv1.3 TLSv1.2 TLSv1.1 TLSv1; ssl_prefer_server_ciphers on; ssl_ciphers EECDH+AESGCM:EDH+AESGCM; ssl_ecdh_curve secp384r1; ssl_session_timeout 10m; ssl_session_cache shared:SSL:10m; ssl_session_tickets off; ssl_stapling on; ssl_stapling_verify on; # Security Headers add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always; add_header Content-Security-Policy "default-src 'none'; script-src 'self' 'unsafe-inline'; img-src 'self'; style-src 'self' 'unsafe-inline'; font-src 'self'; object-src 'none'; media-src 'self' blob: video.twimg.com; worker-src 'self' blob:; base-uri 'self'; form-action 'self'; frame-ancestors 'self'; connect-src 'self' https://*.twimg.com; manifest-src 'self'"; add_header X-Content-Type-Options nosniff; add_header X-Frame-Options DENY; add_header X-XSS-Protection "1; mode=block"; location / { proxy_pass http://localhost:YOUR_NITTER_PORT; } location = /robots.txt { add_header Content-Type text/plain; return 200 "User-agent: *\nDisallow: /\n"; } } ``` -------------------------------- ### Apache Configuration: Proxy Nitter over HTTPS Source: https://github.com/zedeus/nitter/wiki/Apache This Apache virtual host configuration sets up Nitter to be served securely over HTTPS. It includes proxy settings to forward requests to the Nitter instance running on a specific port and configures SSL/TLS using Let's Encrypt certificates. Ensure `mod_ssl` and related modules are enabled. ```apache ServerName YOUR_DOMAIN # Logging ErrorLog ${APACHE_LOG_DIR}/nitter.error.log CustomLog ${APACHE_LOG_DIR}/nitter.access.log combined # Nitter Proxy Configuration ProxyPreserveHost On ProxyPass / http://127.0.0.1:NITTER_PORT/ nocanon ProxyPassReverse / http://127.0.0.1:NITTER_PORT/ AllowEncodedSlashes On # Lets Encrypt TLS Settings SSLEngine on SSLCertificateFile /etc/letsencrypt/live/YOUR_DOMAIN/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/YOUR_DOMAIN/privkey.pem Include /etc/letsencrypt/options-ssl-apache.conf ``` -------------------------------- ### Apache Configuration: Force HTTPS Redirect for Nitter Source: https://github.com/zedeus/nitter/wiki/Apache This Apache virtual host configuration redirects all HTTP traffic to HTTPS, ensuring secure connections to Nitter. It requires the `mod_proxy_http` module to be enabled. The configuration specifies the domain, logging paths, and the redirection rule. ```apache ServerName YOUR_DOMAIN # force https Redirect / https://YOUR_DOMAIN # logging ErrorLog ${APACHE_LOG_DIR}/nitter.error.log CustomLog ${APACHE_LOG_DIR}/nitter.access.log combined ``` -------------------------------- ### Build Nitter Project with User Creation Source: https://github.com/zedeus/nitter/blob/master/README.md This snippet demonstrates the process of setting up a dedicated user for Nitter, cloning the repository, and building the project along with its associated SCSS and Markdown files. It requires root privileges for user creation and assumes a Linux-like environment. ```bash # useradd -m nitter ``` -------------------------------- ### Run Prebuilt Nitter Docker Image Source: https://github.com/zedeus/nitter/blob/master/README.md Runs a prebuilt Nitter Docker image as a detached container, mounting the local nitter.conf file for configuration and using the host network. This is a simpler way to run Nitter with Docker if you don't need to build the image yourself. ```bash docker run -v $(pwd)/nitter.conf:/src/nitter.conf -d --network host zedeus/nitter:latest ``` -------------------------------- ### Nitter Docker Deployment (Bash & YAML) Source: https://context7.com/zedeus/nitter/llms.txt Provides instructions and configurations for deploying Nitter using Docker. This includes building a custom Docker image, running Nitter with a configuration file, and a `docker-compose.yml` file for orchestrating Nitter and its Redis dependency. This simplifies the deployment process and ensures consistent environments. ```bash # Build custom image docker build -t nitter:latest . # Run with configuration file docker run -v $(pwd)/nitter.conf:/src/nitter.conf \ -v $(pwd)/sessions.jsonl:/src/sessions.jsonl:ro \ -d --network host nitter:latest # Docker Compose with Redis docker-compose up -d ``` ```yaml version: "3" services: nitter: image: zedeus/nitter:latest container_name: nitter ports: - "127.0.0.1:8080:8080" volumes: - ./nitter.conf:/src/nitter.conf:Z,ro - ./sessions.jsonl:/src/sessions.jsonl:Z,ro depends_on: - nitter-redis restart: unless-stopped healthcheck: test: wget -nv --tries=1 --spider http://127.0.0.1:8080/Jack/status/20 || exit 1 interval: 30s timeout: 5s retries: 2 nitter-redis: image: redis:6-alpine container_name: nitter-redis command: redis-server --save 60 1 --loglevel warning volumes: - nitter-redis:/data restart: unless-stopped volumes: nitter-redis: ``` -------------------------------- ### Build and Run Nitter with Docker Source: https://github.com/zedeus/nitter/blob/master/README.md Builds a Docker image for Nitter and then runs it as a detached container. It mounts the local nitter.conf file into the container for configuration and uses the host network. An alternative Dockerfile for ARM64 is also mentioned. ```bash docker build -t nitter:latest . docker run -v $(pwd)/nitter.conf:/src/nitter.conf -d --network host nitter:latest ``` -------------------------------- ### Run Nitter and Redis with Docker Compose Source: https://github.com/zedeus/nitter/blob/master/README.md Uses docker-compose to spin up Nitter and Redis as separate containers. This requires modifying the nitter.conf file to set the Redis host to 'nitter-redis' and assumes a docker-compose.yml file is present. ```bash docker-compose up -d ``` -------------------------------- ### View Nitter Logs with Docker Source: https://github.com/zedeus/nitter/blob/master/README.md Displays the logs of a running Nitter Docker container. The `--follow` flag can be used to stream logs in real-time. Replace '*nitter container id*' with the actual ID of the container. ```bash docker logs --follow *nitter container id* ``` -------------------------------- ### Systemd Service Configuration Source: https://context7.com/zedeus/nitter/llms.txt Instructions for configuring and managing the Nitter service using systemd. ```APIDOC ## Systemd Service Unit File ### Description Configuration file for the Nitter systemd service. ### File Content ```ini [Unit] Description=Nitter (An alternative Twitter front-end) After=syslog.target After=network.target [Service] Type=simple User=nitter Group=nitter WorkingDirectory=/home/nitter/nitter ExecStart=/home/nitter/nitter/nitter Restart=always RestartSec=15 [Install] WantedBy=multi-user.target ``` ## Enable and Start Service ### Description Commands to enable, start, and manage the Nitter systemd service. ### Commands 1. **Copy service file:** ```bash sudo cp nitter.service /etc/systemd/system/ ``` 2. **Enable and start the service:** ```bash sudo systemctl enable --now nitter.service ``` 3. **Check service status:** ```bash sudo systemctl status nitter.service ``` 4. **View service logs:** ```bash journalctl -u nitter.service --follow ``` ``` -------------------------------- ### Media Proxy Routes Source: https://context7.com/zedeus/nitter/llms.txt Placeholder for Media Proxy Routes documentation. This section is currently empty. -------------------------------- ### View Nitter Logs with journalctl Source: https://github.com/zedeus/nitter/blob/master/README.md Retrieves logs for the Nitter systemd service. The `--follow` flag can be added to stream new log entries in real-time. ```bash journalctl -u nitter.service ``` -------------------------------- ### Create Nitter Session using Browser Automation (Python) Source: https://github.com/zedeus/nitter/wiki/Creating-session-tokens This script uses browser automation to create a Nitter session by logging in with provided username and password. It supports 2FA if a TOTP secret is supplied. The session is appended to a specified `.jsonl` file. Consider using proxies/VPNs for multiple sessions. ```sh pip install -r requirements.txt python3 create_session_browser.py [totp_secret] --append ../sessions.jsonl ``` -------------------------------- ### Shell Command to Copy Fail2ban Jail Configuration Source: https://github.com/zedeus/nitter/wiki/Rate-Limiting-‐-Nginx Copies the default Fail2ban jail configuration file (`jail.conf`) to a local version (`jail.local`). Fail2ban prioritizes `jail.local`, allowing for custom overrides without modifying the original configuration files. ```bash cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local ``` -------------------------------- ### Nitter systemd Service File Source: https://github.com/zedeus/nitter/blob/master/README.md A systemd service file to manage Nitter as a background service. It defines the service description, user, group, working directory, and the command to execute. It also configures the service to restart automatically if it fails. ```ini [Unit] Description=Nitter (An alternative Twitter front-end) After=syslog.target After=network.target [Service] Type=simple # set user and group User=nitter Group=nitter # configure location WorkingDirectory=/home/nitter/nitter ExecStart=/home/nitter/nitter/nitter Restart=always RestartSec=15 [Install] WantedBy=multi-user.target ``` -------------------------------- ### Configure Caddy Rate Limiting for Nitter Source: https://github.com/zedeus/nitter/wiki/Rate-Limiting-‐-Caddy This configuration snippet sets up rate limiting for a Nitter instance using Caddy. It defines a matcher to exclude static assets from rate limiting and applies rules for requests per second and per minute. It also includes standard security headers and optional log discarding. ```caddyfile nitter.example.com { @notstatic { not path /css/* /js/* /fonts/* /browserconfig.xml /android-chrome* /favicon* /logo* /lp.svg /robots.txt /safari* /site.webmanifest /pic/* } rate_limit @notstatic {remote.ip} 2r/s 60000 500 rate_limit @notstatic {remote.ip} 30r/m 300000 500 reverse_proxy localhost:8080 { transport http {compression off} } header { Strict-Transport-Security "max-age=63072000" Referrer-Policy no-referrer X-Permitted-Cross-Domain-Policies none X-Content-Type-Options nosniff Permissions-Policy "Permissions-Policy: accelerometer=(), ambient-light-sensor=(), autoplay=(self), battery=(), camera=(), cross-origin-isolated=(), display-capture=(), document-domain=(), encrypted-media=(), execution-while-not-rendered=(), execution-while-out-of-viewport=(), fullscreen=(self), geolocation=(), gyroscope=(), keyboard-map=(), magnetometer=(), microphone=(), midi=(), navigation-override=(), payment=(), picture-in-picture=(self), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(), usb=(), web-share=(), xr-spatial-tracking=()" header Content-Security-Policy "default-src 'none'; script-src 'self' 'unsafe-inline'; img-src 'self'; style-src 'self' 'unsafe-inline'; font-src 'self'; object-src 'none'; media-src 'self' blob:; worker-src 'self' blob:; base-uri 'self'; form-action 'self'; frame-ancestors 'self'; connect-src 'self' https://*.twimg.com; manifest-src 'self'" } # Optional: discard logs completely log { output discard } } ``` -------------------------------- ### Image, Video, and GIF Proxy Source: https://context7.com/zedeus/nitter/llms.txt Endpoints for proxying images, videos, and GIFs through Nitter. This is useful for serving media content via Nitter's domain. ```APIDOC ## Image Proxy ### Description Proxies an image through Nitter. ### Method GET ### Endpoint /pic/@encoded_url ## Video Proxy ### Description Proxies a video through Nitter. ### Method GET ### Endpoint /video/@encoded_url ## GIF Proxy ### Description Proxies a GIF through Nitter. ### Method GET ### Endpoint /gif/@encoded_url ### Example `http://localhost:8080/pic/encoded_media_url` ``` -------------------------------- ### Create Nitter Session using HTTP Requests (Python) Source: https://github.com/zedeus/nitter/wiki/Creating-session-tokens An alternative script that creates Nitter sessions using HTTP requests via `curl_cffi`, offering faster performance than browser automation. It requires username, password, and optionally a TOTP secret for 2FA. Sessions are appended to a `.jsonl` file. This method might be more prone to bot detection. ```sh pip install -r requirements.txt python3 create_session_curl.py [totp_secret] --append ../sessions.jsonl ``` -------------------------------- ### Nitter Session File Format (JSONL) Source: https://github.com/zedeus/nitter/wiki/Creating-session-tokens Defines the structure of the `sessions.jsonl` file, which stores authentication cookies and user information for Nitter. This file must be in JSONL (NDJSON) format and is used to load sessions for API requests. Username and ID are optional but recommended for easier monitoring. ```json {"kind": "cookie", "auth_token": "...", "ct0": "...", "username": "...", "id": "..."} {"kind": "cookie", "auth_token": "...", "ct0": "...", "username": "...", "id": "..."} ``` -------------------------------- ### Nitter Systemd Service Unit File (INI) Source: https://context7.com/zedeus/nitter/llms.txt Configuration for a systemd service unit file for Nitter. It defines the service description, execution command, user, and restart policies. ```ini [Unit] Description=Nitter (An alternative Twitter front-end) After=syslog.target After=network.target [Service] Type=simple User=nitter Group=nitter WorkingDirectory=/home/nitter/nitter ExecStart=/home/nitter/nitter/nitter Restart=always RestartSec=15 [Install] WantedBy=multi-user.target ``` -------------------------------- ### Fetch Paginated Tweets (Nim) Source: https://context7.com/zedeus/nitter/llms.txt Demonstrates fetching tweets with pagination. It retrieves the first page of tweets and then uses the 'bottom' cursor to fetch the subsequent page, showcasing sequential data retrieval. ```nim import asyncdispatch, api, types, query # Fetch with pagination proc fetchPaginated() {.async.} = let userId = await getUserId("nim_lang") var profile = await getGraphUserTweets(userId, TimelineKind.tweets) echo "First page: ", profile.tweets.content.len, " tweets" echo "Next cursor: ", profile.tweets.bottom # Fetch next page profile = await getGraphUserTweets( userId, TimelineKind.tweets, profile.tweets.bottom ) echo "Second page: ", profile.tweets.content.len, " tweets" waitFor fetchPaginated() ``` -------------------------------- ### Fetch User Profile by Username (Nim) Source: https://context7.com/zedeus/nitter/llms.txt Fetches a user's profile information including username, full name, bio, follower counts, and verification status. Requires the 'asyncdispatch', 'api', and 'types' modules. ```nim import asyncdispatch, api, types # Fetch user profile by username proc fetchUserProfile() {.async.} = let user = await getGraphUser("jack") echo "Username: ", user.username echo "Full name: ", user.fullname echo "Bio: ", user.bio echo "Followers: ", user.followers echo "Following: ", user.following echo "Verified: ", user.verifiedType waitFor fetchUserProfile() ``` -------------------------------- ### Nitter Server Configuration (INI) Source: https://context7.com/zedeus/nitter/llms.txt Defines the server, caching, configuration, and user preference settings for Nitter. This includes hostname, port, cache durations, Redis connection details, security keys, and UI theme options. The configuration is essential for setting up a self-hosted Nitter instance. ```ini [Server] hostname = "nitter.example.com" title = "nitter" address = "0.0.0.0" port = 8080 https = true httpMaxConnections = 100 staticDir = "./public" [Cache] listMinutes = 240 rssMinutes = 10 redisHost = "localhost" redisPort = 6379 redisPassword = "" redisConnections = 20 redisMaxConnections = 30 [Config] hmacKey = "your-random-secret-key-here" base64Media = false enableRSS = true enableDebug = false proxy = "" proxyAuth = "" apiProxy = "" disableTid = false maxConcurrentReqs = 2 [Preferences] theme = "Nitter" replaceTwitter = "nitter.example.com" replaceYouTube = "piped.video" replaceReddit = "teddit.net" proxyVideos = true hlsPlayback = false infiniteScroll = false ``` -------------------------------- ### Timeline Fetching API Source: https://context7.com/zedeus/nitter/llms.txt APIs for fetching user timelines, including pagination. ```APIDOC ## Fetch User Tweets ### Description Fetches a user's tweets. ### Method GET ### Endpoint /api/tweets/{username} ### Parameters #### Path Parameters - **username** (string) - Required - The username of the user whose tweets to fetch. #### Query Parameters - **after** (string) - Optional - Cursor for fetching the next page of tweets. ### Response #### Success Response (200) - **tweets** (object) - Contains tweet content and pagination info. - **content** (array) - An array of tweet objects. - **id** (string) - The ID of the tweet. - **text** (string) - The content of the tweet. - **likes** (integer) - The number of likes on the tweet. - **retweets** (integer) - The number of retweets. - **bottom** (string) - Cursor for the next page of results. ### Response Example ```json { "tweets": { "content": [ { "id": "123", "text": "Hello world!", "likes": 10, "retweets": 5 } ], "bottom": "next_cursor_string" } } ``` ## Fetch User Tweets with Pagination ### Description Fetches user tweets with support for pagination to retrieve older tweets. ### Method GET ### Endpoint /api/tweets/{username} ### Parameters #### Path Parameters - **username** (string) - Required - The username of the user whose tweets to fetch. #### Query Parameters - **after** (string) - Optional - Cursor for fetching the next page of tweets. ### Response #### Success Response (200) - **tweets** (object) - Contains tweet content and pagination info. - **content** (array) - An array of tweet objects. - **bottom** (string) - Cursor for the next page of results. ### Response Example ```json { "tweets": { "content": [ { "id": "456", "text": "Pagination example.", "likes": 20, "retweets": 8 } ], "bottom": "another_cursor" } } ``` ``` -------------------------------- ### Nginx Server Block Configuration for Nitter Static Assets Source: https://github.com/zedeus/nitter/wiki/Rate-Limiting-‐-Nginx Configures Nginx locations to serve Nitter's static assets and media using the previously defined shared cache and static configurations. This includes media files, CSS, JavaScript, and various icons. ```nginx server { location /pic/ { include shared_cache.conf; } location /video/ { include shared_cache.conf; } # If you are running nitter from docker then change `shared_static.conf` to `shared_cache.conf` location /css/ { include shared_static.conf; } location /js/ { include shared_static.conf; } location /fonts/ { include shared_static.conf; } location = /apple-touch-icon.png { include shared_static.conf; } location = /apple-touch-icon-precomposed.png { include shared_static.conf; } location = /android-chrome-192x192.png { include shared_static.conf; } location = /favicon-32x32.png { include shared_static.conf; } location = /favicon-16x16.png { include shared_static.conf; } location = /favicon.ico { include shared_static.conf; } location = /logo.png { include shared_static.conf; } location = /site.webmanifest { include shared_static.conf; } } ``` -------------------------------- ### Nginx Error Logging Configuration for Fail2ban Source: https://github.com/zedeus/nitter/wiki/Rate-Limiting-‐-Nginx Enables Nginx error logging at a 'notice' level, directing output to a specified file. This is crucial for Fail2ban to monitor and identify excessive request attempts for effective IP banning. ```nginx error_log /var/log/nginx/nitter_error.log notice; ``` -------------------------------- ### Shell Command to Restart Fail2ban Service Source: https://github.com/zedeus/nitter/wiki/Rate-Limiting-‐-Nginx Restarts the Fail2ban service to apply any changes made to its configuration files, such as enabling new jails or modifying existing settings like ban times. ```bash systemctl restart fail2ban ``` -------------------------------- ### Shell Command to Reload Nginx Configuration Source: https://github.com/zedeus/nitter/wiki/Rate-Limiting-‐-Nginx A bash command to gracefully reload Nginx configuration files without interrupting active connections. This applies any changes made to Nginx configuration, including rate limiting rules. ```bash nginx -s reload ``` -------------------------------- ### Python Twitter Authentication and Session Management Source: https://context7.com/zedeus/nitter/llms.txt This Python script handles Twitter authentication using username, password, and a 2FA secret. It obtains bearer and guest tokens, performs a login flow, and manages 2FA if required. The resulting session tokens are saved to a JSONL file. Dependencies include 'requests', 'cloudscraper', and 'pyotp'. ```python TW_CONSUMER_KEY = '3nVuSoBZnx6U4vzUxf5w' TW_CONSUMER_SECRET = 'Bcs59EFbbsdF6Sl9Ng71smgStWEGwXXKSjYvPVt7qys' def auth(username, password, otp_secret): # Get bearer token bearer_token_req = requests.post( "https://api.twitter.com/oauth2/token", auth=(TW_CONSUMER_KEY, TW_CONSUMER_SECRET), headers={"Content-Type": "application/x-www-form-urlencoded"}, data='grant_type=client_credentials' ) bearer_token = ' '.join(str(x) for x in bearer_token_req.json().values()) # Get guest token guest_token = requests.post( "https://api.twitter.com/1.1/guest/activate.json", headers={'Authorization': bearer_token} ).json().get('guest_token') if not guest_token: print("Failed to obtain guest token.") sys.exit(1) # Create scraper with headers scraper = cloudscraper.create_scraper() scraper.headers = { 'Authorization': bearer_token, "Content-Type": "application/json", "X-Twitter-API-Version": '5', "X-Twitter-Client": "TwitterAndroid", "X-Guest-Token": guest_token } # Login flow task1 = scraper.post( 'https://api.twitter.com/1.1/onboarding/task.json', params={'flow_name': 'login', 'api_version': '1'}, json={"flow_token": None, "input_flow_data": {...}} ) task2 = scraper.post( 'https://api.twitter.com/1.1/onboarding/task.json', json={ "flow_token": task1.json().get('flow_token'), "subtask_inputs": [{ "enter_text": {"text": username, "link": "next_link"}, "subtask_id": "LoginEnterUserIdentifier" }] } ) task3 = scraper.post( 'https://api.twitter.com/1.1/onboarding/task.json', json={ "flow_token": task2.json().get('flow_token'), "subtask_inputs": [{ "enter_password": {"password": password, "link": "next_link"}, "subtask_id": "LoginEnterPassword" }] } ) # Handle 2FA if needed for subtask in task3.json().get('subtasks', []): if "enter_text" in subtask: totp = pyotp.TOTP(otp_secret) task4 = scraper.post( "https://api.twitter.com/1.1/onboarding/task.json", json={ "flow_token": task3.json().get("flow_token"), "subtask_inputs": [{ "enter_text": {"text": totp.now()}, "subtask_id": "LoginTwoFactorAuthChallenge" }] } ) return task4.json()['subtasks'][0]["open_account"] elif "open_account" in subtask: return subtask["open_account"] # Run authentication result = auth("twitter_username", "password", "2FA_SECRET") session_entry = { "oauth_token": result.get("oauth_token"), "oauth_token_secret": result.get("oauth_token_secret") } with open("sessions.jsonl", "a") as f: f.write(json.dumps(session_entry) + "\n") ``` -------------------------------- ### Tweet and Thread Routes Source: https://context7.com/zedeus/nitter/llms.txt Endpoints for retrieving individual tweets and their associated threads, as well as paginating replies to a specific tweet. ```APIDOC ## Tweet and Thread Routes ### Description Endpoints for retrieving individual tweets and their associated threads, as well as paginating replies to a specific tweet. ### Method GET ### Endpoint - `/@username/status/@tweet_id` - `/@username/status/@tweet_id?cursor=reply_cursor` ### Parameters #### Path Parameters - **username** (string) - Required - The username of the tweet's author. - **tweet_id** (string) - Required - The ID of the tweet. #### Query Parameters - **cursor** (string) - Optional - The cursor for fetching the next page of replies. ### Request Example ```bash curl http://localhost:8080/jack/status/20 ``` ### Response #### Success Response (200) - Returns the specified tweet and its thread context. #### Response Example ```json { "tweet_id": "20", "text": "First tweet on Twitter!", "author": "@jack", "thread": [ // ... other tweets in the thread ] } ``` ``` -------------------------------- ### Nim User Timeline Web Routes Source: https://context7.com/zedeus/nitter/llms.txt These Nim web routes provide access to user profiles and timelines on Twitter. They support fetching a user's main timeline, tweets with replies, media-only timelines, and searching within a user's tweets. The routes also handle multiple user timelines and redirection for user IDs. ```nim # User profile and timeline GET /@username GET /@username/with_replies GET /@username/media GET /@username/search?q=query # Multiple user timeline GET /@user1,user2,user3 # User by ID redirect GET /i/user/@user_id GET /intent/user?user_id=123456 # Infinite scroll pagination GET /@username?scroll=true&cursor=DAABCgABGKxDVQ0 # Example: curl http://localhost:8080/elonmusk # Returns: HTML page with latest tweets from @elonmusk # Example: curl http://localhost:8080/elonmusk/media # Returns: Media-only timeline for @elonmusk ``` -------------------------------- ### User Timeline Routes Source: https://context7.com/zedeus/nitter/llms.txt Endpoints for retrieving user profiles, timelines, and media. Supports filtering by replies and searching within a user's tweets. Also handles fetching timelines for multiple users and redirects for user IDs. ```APIDOC ## User Timeline Routes ### Description Endpoints for retrieving user profiles, timelines, and media. Supports filtering by replies and searching within a user's tweets. Also handles fetching timelines for multiple users and redirects for user IDs. ### Method GET ### Endpoint - `/@username` - `/@username/with_replies` - `/@username/media` - `/@username/search?q=query` - `/@user1,user2,user3` - `/i/user/@user_id` - `/intent/user?user_id=123456` - `/@username?scroll=true&cursor=DAABCgABGKxDVQ0` ### Query Parameters - **q** (string) - Required - The search query for user tweets. - **scroll** (boolean) - Optional - Enables infinite scroll pagination. - **cursor** (string) - Optional - The cursor for fetching the next page of results. - **f** (string) - Optional - Filter for search results (e.g., 'tweets', 'users'). - **user_id** (string) - Required - The ID of the user to redirect to. ### Request Example ```bash curl http://localhost:8080/elonmusk ``` ### Response #### Success Response (200) - Returns HTML page with tweets for the specified user. #### Response Example ```html ``` ``` -------------------------------- ### RSS Feed Routes Source: https://context7.com/zedeus/nitter/llms.txt Endpoints for generating RSS feeds for user timelines, searches, and lists. ```APIDOC ## RSS Feed Routes ### Description Endpoints for generating RSS feeds for user timelines, searches, and lists. ### Method GET ### Endpoint - `/@username/rss` - `/@username/with_replies/rss` - `/@username/media/rss` - `/search/rss?q=query` - `/@username/lists/@slug/rss` - `/i/lists/@list_id/rss` ### Query Parameters - **q** (string) - Required for search RSS - The search query. ### Request Example ```bash curl http://localhost:8080/nim_lang/rss ``` ### Response #### Success Response (200) - Returns an RSS feed in XML format. #### Response Example ```xml RSS Feed Tweet Title tweet_url Tweet content ``` ``` -------------------------------- ### Search Users by Query (Nim) Source: https://context7.com/zedeus/nitter/llms.txt Searches for users based on a text query. It returns a list of users, including their username, full name, and follower count, useful for discovering accounts. ```nim import asyncdispatch, api, query, types # Search users proc searchUsers() {.async.} = let q = Query(kind: users, text: "programmer") let results = await getGraphUserSearch(q, after="") for user in results.content: echo "Username: @", user.username echo "Name: ", user.fullname echo "Followers: ", user.followers echo "---" waitFor searchUsers() ``` -------------------------------- ### Nim Tweet and Thread Web Routes Source: https://context7.com/zedeus/nitter/llms.txt This Nim route allows fetching a single tweet along with its full thread context. It also supports paginating replies to a specific tweet using a cursor. The endpoint is designed to retrieve detailed tweet information. ```nim # Single tweet with thread GET /@username/status/@tweet_id # Tweet replies pagination GET /@username/status/@tweet_id?cursor=reply_cursor # Example: curl http://localhost:8080/jack/status/20 # Returns: First tweet on Twitter with full thread context ``` -------------------------------- ### Shell Command to Check Fail2ban Jail Status Source: https://github.com/zedeus/nitter/wiki/Rate-Limiting-‐-Nginx Verifies the operational status of a specific Fail2ban jail, in this case, `nginx-limit-req`. It displays the number of current and total failed attempts and banned IPs, confirming that the rate-limiting protection is active. ```bash fail2ban-client status nginx-limit-req ``` -------------------------------- ### Fail2ban Jail Configuration for Nginx Rate Limiting Source: https://github.com/zedeus/nitter/wiki/Rate-Limiting-‐-Nginx This Fail2ban configuration snippet enables the monitoring and banning of IP addresses that violate Nginx rate limits. It requires the `nginx-limit-req` jail to be enabled and points to the Nginx error log for monitoring. ```fail2ban [nginx-limit-req] enabled = true port = http,https logpath = %(nginx_error_log)s ``` -------------------------------- ### Fetch List by Slug (Nim) Source: https://context7.com/zedeus/nitter/llms.txt Retrieves a Twitter list's details (name, description, member count) using the list owner's username and the list's slug. This function is useful for accessing curated collections of users. ```nim import asyncdispatch, api, types # Fetch list by slug proc fetchListBySlug() {.async.} = let list = await getGraphListBySlug("jack", "test-list") echo "List: ", list.name echo "Description: ", list.description echo "Members: ", list.members waitFor fetchListBySlug() ``` -------------------------------- ### Fail2ban Configuration for Incremental Ban Time Source: https://github.com/zedeus/nitter/wiki/Rate-Limiting-‐-Nginx Ensures that Fail2ban's ban time increases with subsequent offenses from the same IP address. This setting is configured within the `jail.local` file to implement escalating punishments for repeat offenders. ```fail2ban bantime.increment = true ``` -------------------------------- ### Fetch Tweet Thread (Nim) Source: https://context7.com/zedeus/nitter/llms.txt Retrieves a full tweet thread, including the main tweet and all its replies. It displays the main tweet's text and author, followed by the content of each reply. ```nim import asyncdispatch, api, types # Fetch tweet thread proc fetchThread() {.async.} = let tweetId = "20" let conversation = await getTweet(tweetId) echo "Main tweet:" echo conversation.tweet.text echo "By: @", conversation.tweet.user.username echo "\nReplies:" for chain in conversation.replies.content: for tweet in chain.content: echo " @", tweet.user.username, ": ", tweet.text waitFor fetchThread() ``` -------------------------------- ### Search Routes Source: https://context7.com/zedeus/nitter/llms.txt Endpoints for searching tweets and users based on a query. Also includes a redirect for hashtag searches. ```APIDOC ## Search Routes ### Description Endpoints for searching tweets and users based on a query. Also includes a redirect for hashtag searches. ### Method GET ### Endpoint - `/search?q=query&f=tweets` - `/search?q=username&f=users` - `/hashtag/nim` ### Query Parameters - **q** (string) - Required - The search query. - **f** (string) - Required - The filter for search results ('tweets' or 'users'). ### Request Example ```bash curl "http://localhost:8080/search?q=nim%20lang&f=tweets" ``` ### Response #### Success Response (200) - Returns search results matching the query and filter. #### Response Example ```json { "results": [ // ... tweets or users matching the search query ] } ``` ``` -------------------------------- ### User Data Fetching API Source: https://context7.com/zedeus/nitter/llms.txt APIs for fetching user profile information by username or user ID. ```APIDOC ## Fetch User Profile by Username ### Description Fetches a user's profile information using their username. ### Method GET ### Endpoint /api/users/{username} ### Parameters #### Path Parameters - **username** (string) - Required - The username of the user to fetch. ### Response #### Success Response (200) - **username** (string) - The user's username. - **fullname** (string) - The user's full name. - **bio** (string) - The user's biography. - **followers** (integer) - The number of followers the user has. - **following** (integer) - The number of users the user is following. - **verifiedType** (string) - The verification status of the user. ### Response Example ```json { "username": "jack", "fullname": "Jack Dorsey", "bio": "Bitcoin", "followers": 1000000, "following": 200, "verifiedType": "Blue" } ``` ## Fetch User by ID ### Description Fetches user information using their unique ID. ### Method GET ### Endpoint /api/users/id/{userId} ### Parameters #### Path Parameters - **userId** (string) - Required - The ID of the user to fetch. ### Response #### Success Response (200) - **username** (string) - The user's username. ### Response Example ```json { "username": "exampleUser" } ``` ``` -------------------------------- ### Thread and Conversation API Source: https://context7.com/zedeus/nitter/llms.txt APIs for fetching tweet threads and paginating replies to a tweet. ```APIDOC ## Fetch Tweet Thread ### Description Fetches a specific tweet along with its replies, forming a conversation thread. ### Method GET ### Endpoint /api/tweet/{tweetId} ### Parameters #### Path Parameters - **tweetId** (string) - Required - The ID of the main tweet in the thread. ### Response #### Success Response (200) - **tweet** (object) - The main tweet object. - **text** (string) - The content of the main tweet. - **user** (object) - Information about the author of the main tweet. - **username** (string) - The author's username. - **replies** (object) - Contains nested replies. - **content** (array) - An array where each element contains an array of reply tweet objects. - **user** (object) - Information about the reply author. - **username** (string) - The reply author's username. - **text** (string) - The content of the reply. ### Response Example ```json { "tweet": { "text": "This is the main tweet.", "user": { "username": "mainUser" } }, "replies": { "content": [ [ { "user": { "username": "replyUser1" }, "text": "This is a reply." } ] ] } } ``` ## Fetch Replies with Pagination ### Description Fetches replies to a specific tweet, with support for pagination. ### Method GET ### Endpoint /api/replies/{tweetId} ### Parameters #### Path Parameters - **tweetId** (string) - Required - The ID of the tweet whose replies to fetch. #### Query Parameters - **after** (string) - Optional - Cursor for fetching the next page of replies. ### Response #### Success Response (200) - **content** (array) - An array of reply tweet objects. - **bottom** (string) - Cursor for the next page of results. ### Response Example ```json { "content": [ { "user": { "username": "replyUser" }, "text": "Another reply." } ], "bottom": "replies_cursor" } ``` ``` -------------------------------- ### List Routes Source: https://context7.com/zedeus/nitter/llms.txt Endpoints for accessing Twitter lists by their slug or ID, and retrieving members of a list. ```APIDOC ## List Routes ### Description Endpoints for accessing Twitter lists by their slug or ID, and retrieving members of a list. ### Method GET ### Endpoint - `/@username/lists/@slug` - `/i/lists/@list_id` - `/@username/lists/@slug/members` - `/i/lists/@list_id/members` ### Parameters #### Path Parameters - **username** (string) - Required - The username who owns the list. - **slug** (string) - Required - The slug of the list. - **list_id** (string) - Required - The ID of the list. ### Request Example ```bash curl http://localhost:8080/jack/lists/test-list ``` ### Response #### Success Response (200) - Returns the timeline of tweets from the specified list or its members. #### Response Example ```json { "tweets": [ // ... tweets from users in the list ] } ``` ``` -------------------------------- ### Nginx Main Location Rate Limiting Configuration Source: https://github.com/zedeus/nitter/wiki/Rate-Limiting-‐-Nginx Applies rate limiting to the main Nitter application location. It uses defined zones (`nitter.tld_sec` and `nitter.tld_min`) with specified burst limits to allow temporary traffic spikes while enforcing overall rate restrictions. ```nginx server { location / { proxy_pass http://localhost:8080; limit_req zone=nitter.tld_sec burst=3 nodelay; limit_req zone=nitter.tld_min burst=4; } } ``` -------------------------------- ### Nim List Web Routes Source: https://context7.com/zedeus/nitter/llms.txt These Nim routes provide access to Twitter lists. You can retrieve a list by its slug or ID, and also fetch the members of a specific list. These endpoints are useful for accessing curated collections of users or tweets. ```nim # List by slug GET /@username/lists/@slug # List by ID GET /i/lists/@list_id # List members GET /@username/lists/@slug/members GET /i/lists/@list_id/members # Example: curl http://localhost:8080/jack/lists/test-list # Returns: Timeline of tweets from list "test-list" by @jack ```