Search Operations
Search for tweets and users on X/Twitter.
searchTweets
Search for tweets by keyword or hashtag.
Description
Searches for tweets matching a query string. Supports advanced search operators, filters, and sorting. In crawler mode, uses web scraping to return tweets without API rate limits. Returns tweet objects with basic author information (username, name) but NOT bio or follower counts.
Important: Twitter's SearchTimeline API doesn't include author bio or follower metrics. To get complete profile data, use enrichTweetAuthors() after searching.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
query | string | Yes | Search query (keywords, hashtags, operators) |
options | SearchTweetsOptions | No | Search options |
SearchTweetsOptions Interface
| Property | Type | Default | Description |
|---|---|---|---|
maxResults | number | 20 | Maximum tweets to return (1-100) |
Returns
| Type | Description |
|---|---|
Promise<Tweet[]> | Array of matching tweets with basic author data |
Examples
Basic Search
import { XTwitterClient } from '@blockchain-web-services/bws-x-sdk-node';
const client = new XTwitterClient({ mode: 'crawler' });
const tweets = await client.searchTweets('blockchain', {
maxResults: 50
});
tweets.forEach(tweet => {
console.log(`@${tweet.author.username}: ${tweet.text}`);
console.log(`Likes: ${tweet.metrics.likes}, Retweets: ${tweet.metrics.retweets}\n`);
});Search with Author Enrichment
// Search for tweets
const tweets = await client.searchTweets('blockchain credentials', {
maxResults: 30
});
// Enrich authors with bio and follower data
const enriched = await client.enrichTweetAuthors(tweets);
// Now you have complete profile data
enriched.forEach(tweet => {
console.log(`@${tweet.author.username} (${tweet.author.followers} followers)`);
console.log(`Bio: ${tweet.author.bio}`);
console.log(`Tweet: ${tweet.text}\n`);
});Advanced Search Query
// Search with Twitter operators
const tweets = await client.searchTweets(
'blockchain credentials min_faves:10 -is:retweet',
{ maxResults: 100 }
);
console.log(`Found ${tweets.length} high-engagement original tweets`);Search and Filter by Author
const tweets = await client.searchTweets('university blockchain', {
maxResults: 50
});
// Pre-filter by author name (free - no API calls needed)
const candidates = tweets.filter(t =>
t.author.name.toLowerCase().match(/university|college|edu/)
);
console.log(`Found ${candidates.length} institutional accounts`);
// Enrich only promising candidates
const enriched = await client.enrichTweetAuthors(candidates);Search Query Operators
Twitter supports advanced search operators in queries:
| Operator | Example | Description |
|---|---|---|
from: | from:elonmusk | Tweets from specific user |
to: | to:vitalikbuterin | Replies to specific user |
@ | @ethereum | Mentions of user |
# | #bitcoin | Hashtag search |
min_faves: | min_faves:10 | Minimum likes |
min_retweets: | min_retweets:5 | Minimum retweets |
-is:retweet | blockchain -is:retweet | Exclude retweets |
-is:reply | defi -is:reply | Exclude replies |
filter:verified | crypto filter:verified | Only verified accounts |
lang: | bitcoin lang:en | Language filter |
since: | since:2024-01-01 | Date range start |
until: | until:2024-12-31 | Date range end |
Author Data Limitation
Important: searchTweets() returns tweets with incomplete author data:
✅ Included in search results:
username- Twitter handlename- Display nameverified- Verification status (if available)
❌ NOT included in search results:
bio- User biography/descriptionfollowers- Follower countfollowing- Following count
Solution: Use enrichTweetAuthors() to fetch complete profile data:
const tweets = await client.searchTweets('query', { maxResults: 50 });
// Pre-filter to reduce enrichment cost
const candidates = tweets.filter(t => /* your criteria */);
// Enrich with full profile data
const enriched = await client.enrichTweetAuthors(candidates);
// Now has bio, followers, following populatedRelated
- enrichTweetAuthors - Get complete author profile data
- searchUsers - Search for users
searchUsers
Search for users by keyword.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
query | string | Yes | Search query |
options | SearchOptions | No | Search options |
Example
const users = await client.searchUsers('crypto influencer');