Skip to content

BWS X SDKNode.js SDK for X/Twitter

Flexible X/Twitter integration with web scraping and API support

BWS X SDK

Quick Example

typescript
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! 🚀');

Why BWS X SDK?

🌟 Flexible Integration Options

Choose the approach that fits your needs:

  • API Mode: Use official Twitter API for guaranteed compatibility
  • Scraping Mode: Use web scraping for specific operations
  • Hybrid Mode: Automatically use the best method for each operation

🔧 Enterprise Features

  • Account Rotation: Distribute load across multiple accounts
  • Error Handling: Comprehensive error types with automatic retry logic
  • Webhook Notifications: Real-time alerts for monitoring and debugging
  • Proxy Support: Built-in support for residential and datacenter proxies
  • TypeScript: Full type safety throughout your application

📈 Use Cases

The SDK is designed to support a wide range of applications:

  • Social Media Monitoring: Track mentions, hashtags, and trends
  • User Analytics: Analyze profiles, followers, and engagement
  • Content Research: Search and analyze tweets at scale
  • Influencer Discovery: Identify and evaluate key opinion leaders
  • Automated Engagement: Schedule and post replies programmatically
  • Data Collection: Gather tweets and profiles for analysis
  • Sentiment Analysis: Collect data for sentiment tracking
  • Community Management: Monitor and engage with communities

Installation

bash
npm install @blockchain-web-services/bws-x-sdk-node
bash
yarn add @blockchain-web-services/bws-x-sdk-node
bash
pnpm add @blockchain-web-services/bws-x-sdk-node

Extract X/Twitter cookies automatically:

bash
npx bws-x-setup-cookies

This interactive wizard extracts and validates your X/Twitter cookies automatically for web scraping mode.

Core Features

Multiple Operating Modes

Switch between API and scraping modes based on your requirements:

typescript
// 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' });

Account Management

Manage multiple accounts with automatic rotation:

typescript
const client = new XTwitterClient({
  crawler: {
    accounts: [
      { id: 'account1', username: '@user1', cookies: {...} },
      { id: 'account2', username: '@user2', cookies: {...} },
    ],
    rotation: {
      cooldownMinutes: 15,
      maxUsesPerHour: 20,
    }
  }
});

Real-time Monitoring

Stay informed with webhook notifications:

typescript
const client = new XTwitterClient({
  webhook: {
    enabled: true,
    url: 'https://your-server.com/webhook',
    secret: 'your-secret',
    events: ['account_failure', 'api_rate_limit']
  }
});

Next Steps

Ready to get started?

Community & Support

License

MIT License

Released under the MIT License.