Hybrid Approach
Combines web scraping with official API access. Choose the best method for each operation or let the SDK decide automatically.
Flexible X/Twitter integration with web scraping and API support
import { XTwitterClient } from '@blockchain-web-services/bws-x-sdk-node';
// Initialize client (uses environment variables)
const client = new XTwitterClient();
// Get tweet with full metrics
const tweet = await client.getTweet('1234567890');
console.log(tweet.text, tweet.metrics);
// Get user profile
const profile = await client.getProfile('username');
console.log(profile.name, profile.metrics.followersCount);
// Search tweets
const results = await client.searchTweets('nodejs', { maxResults: 100 });
// Post a reply
await client.postReply(tweet.id, 'Great insight! 🚀');Choose the approach that fits your needs:
The SDK is designed to support a wide range of applications:
npm install @blockchain-web-services/bws-x-sdk-nodeyarn add @blockchain-web-services/bws-x-sdk-nodepnpm add @blockchain-web-services/bws-x-sdk-nodeExtract X/Twitter cookies automatically:
npx bws-x-setup-cookiesThis interactive wizard extracts and validates your X/Twitter cookies automatically for web scraping mode.
Switch between API and scraping modes based on your requirements:
// API-only mode
const apiClient = new XTwitterClient({ mode: 'api' });
// Scraping-only mode
const scraperClient = new XTwitterClient({ mode: 'crawler' });
// Hybrid mode (automatic fallback)
const hybridClient = new XTwitterClient({ mode: 'hybrid' });Manage multiple accounts with automatic rotation:
const client = new XTwitterClient({
crawler: {
accounts: [
{ id: 'account1', username: '@user1', cookies: {...} },
{ id: 'account2', username: '@user2', cookies: {...} },
],
rotation: {
cooldownMinutes: 15,
maxUsesPerHour: 20,
}
}
});Stay informed with webhook notifications:
const client = new XTwitterClient({
webhook: {
enabled: true,
url: 'https://your-server.com/webhook',
secret: 'your-secret',
events: ['account_failure', 'api_rate_limit']
}
});Ready to get started?
MIT License