X

Interact with X (Twitter) API

Tweet → Search Recent

AI-generated

Overview

This node interacts with the Twitter API (rebranded as "X") to perform various tweet-related actions. Specifically, the Search Recent operation under the Tweet resource allows users to search for recent tweets matching a specified query. It supports filtering by time range and customizing the fields returned in the results.

Common scenarios where this node is beneficial include:

  • Monitoring social media trends or brand mentions in real-time.
  • Gathering recent tweets for sentiment analysis or market research.
  • Automating workflows that react to specific keywords or hashtags on Twitter.

For example, you could use this node to fetch the latest 50 tweets mentioning your company name from the past 24 hours, including detailed user and media information, and then trigger alerts or reports based on the data.

Properties

Name Meaning
Authentication Method of authenticating with Twitter API: either OAuth1.0a or Bearer Token
Query The search query string to find matching tweets
Max Results Maximum number of tweets to return (between 10 and 100)
Start Time ISO 8601 formatted start time to filter tweets created after this timestamp
Additional Fields Optional extra parameters to customize the search results:
- End Time ISO 8601 formatted end time to filter tweets created before this timestamp
- Expansions Comma-separated list of related objects to expand (e.g., author_id, attachments.media_keys)
- Media Fields Comma-separated list of media fields to include (e.g., type, url, preview_image_url)
- Tweet Fields Comma-separated list of tweet fields to include (e.g., author_id, public_metrics, created_at)
- User Fields Comma-separated list of user fields to include (e.g., id, username, public_metrics)

Output

The output is an array of JSON objects representing tweets matching the search criteria. Each object contains tweet data enriched with the requested fields such as author details, media attachments, creation timestamps, and public metrics (like counts, retweets).

If multiple tweets are returned, each tweet is provided as a separate item in the output array.

The node does not output binary data for this operation.

Dependencies

  • Requires valid Twitter API credentials configured in n8n, either via OAuth1.0a or Bearer Token authentication.
  • Uses Twitter API v2 endpoints for searching recent tweets.
  • Optionally falls back to Twitter API v1.1 if no results are found and fallback is enabled (not applicable for this exact operation but related in the broader node context).

Troubleshooting

  • No results returned: Ensure the query string is correctly formed and that the time filters (start/end time) are valid ISO 8601 strings. Also verify that the max results parameter is within allowed limits.
  • Authentication errors: Confirm that the API credentials are correctly set up and have the necessary permissions to access the Twitter API.
  • Rate limiting: Twitter API enforces rate limits; if exceeded, requests may fail temporarily. Consider adding delays or reducing request frequency.
  • Invalid field names in Additional Fields: Using unsupported or misspelled expansions or field names can cause errors. Refer to Twitter API documentation for valid values.

Links and References

Discussion