How to Automate Twitter Posts with API: Complete Guide
Why Automate Twitter Posts?
Manual posting is fine for personal accounts, but if you're running a crypto signal channel, managing a community bot, or publishing market updates — you need automation. The XCROP Write API lets you create tweets, reply to threads, quote-tweet, like, retweet, and follow/unfollow users, all through simple REST endpoints, at a flat 100 credits per operation — a fraction of official Twitter API write pricing.
Connect Your X Account First
Before any of the bots below will work, connect your X account to XCROP — a one-time setup. Full details on credentials vs. cookie auth, proxy requirements, and how your credentials are secured are covered in the [Write API Guide](/blog/write-api-guide); here's the minimal call to get connected:
import requests, os requests.post( "https://xcrop.io/api/v2/account/connect", headers={"Authorization": "Bearer " + os.environ["XCROP_API_KEY"]}, json={ "email": "[email protected]", "password": "your-x-password", "proxy": "http://user:pass@residential-proxy:port" } )
Once connected, every write endpoint (create, reply, quote, like, retweet, follow) works exactly as documented in the [Write API Guide](/blog/write-api-guide) — the rest of this post focuses on stringing those endpoints together into real, running bots.
Practical Automation Examples
Example 1: Scheduled Posting Bot
Post market updates at specific times using a simple scheduler:
import schedule import time import requests import os API_KEY = os.environ["XCROP_API_KEY"] HEADERS = { "Authorization": "Bearer " + API_KEY, "Content-Type": "application/json" } BASE = "https://xcrop.io/api/v2" def morning_update(): # Fetch trending topics first trending = requests.get( BASE + "/trending", headers=HEADERS ).json()["data"] top_topics = [t["name"] for t in trending[:3]] text = ( "GM! Here is what crypto Twitter is talking about today:\n\n" + "1. " + top_topics[0] + "\n" + "2. " + top_topics[1] + "\n" + "3. " + top_topics[2] + "\n\n" + "Stay sharp out there." ) requests.post(BASE + "/tweets/create", headers=HEADERS, json={"text": text}) schedule.every().day.at("08:00").do(morning_update) while True: schedule.run_pending() time.sleep(60)
Example 2: KOL Engagement Bot
Monitor key opinion leaders and auto-engage with high-impact tweets:
const API_KEY = process.env.XCROP_API_KEY; const HEADERS = { "Authorization": "Bearer " + API_KEY, "Content-Type": "application/json" }; const BASE = "https://xcrop.io/api/v2"; async function monitorAndEngage() { // Fetch each KOL's latest tweets and merge them const kols = ["CryptoHayes", "DefiIgnas", "Pentosh1"]; const feeds = await Promise.all( kols.map(u => fetch(BASE + "/users/" + u + "/tweets?count=20", { headers: HEADERS }).then(r => r.json())) ); const tweets = feeds.flatMap(f => f.data || []); for (const tweet of tweets) { const likes = tweet.metrics.likes; // Only engage with viral tweets (5k+ likes) if (likes > 5000) { // Like it await fetch(BASE + "/tweets/" + tweet.tweet_id + "/like", { method: "POST", headers: HEADERS }); // Retweet it await fetch(BASE + "/tweets/" + tweet.tweet_id + "/retweet", { method: "POST", headers: HEADERS }); console.log("Engaged with tweet by @" + tweet.author.username); // Rate limit: wait 30 seconds between actions await new Promise(r => setTimeout(r, 30000)); } } } // Run every 10 minutes setInterval(monitorAndEngage, 600000);
Example 3: Auto-Reply to Mentions
Search for mentions of your project and reply automatically:
import requests import os import time API_KEY = os.environ["XCROP_API_KEY"] HEADERS = { "Authorization": "Bearer " + API_KEY, "Content-Type": "application/json" } BASE = "https://xcrop.io/api/v2" replied_ids = set() def check_mentions(): response = requests.post( BASE + "/search", headers=HEADERS, json={ "query": "@yourproject", "sort": "latest", "count": 10 } ) tweets = response.json()["data"] for tweet in tweets: tid = tweet["tweet_id"] if tid not in replied_ids: requests.post( BASE + "/tweets/reply", headers=HEADERS, json={ "tweet_id": tid, "text": "Thanks for the mention! Check out our docs at https://yourproject.io/docs" } ) replied_ids.add(tid) time.sleep(15) # Space out replies while True: check_mentions() time.sleep(300) # Check every 5 minutes
Responsible Automation
Automation is powerful, but misuse leads to account suspension. Follow these rules:
/account/status regularly to ensure your session is healthyCredit Costs
Every write operation used above — create, reply, quote, like, retweet — costs a flat 100 credits. See the [Write API Guide](/blog/write-api-guide) for the full operation table and plan pricing.