X

Interact with X (Twitter) API

Tweet → Search Recent (v1.1 Fallback)

AI-generated

Overview

This node interacts with Twitter's API to search for recent tweets using either the Twitter API v2 or, as a fallback, the older v1.1 API. It is designed to retrieve tweets based on a user-defined query and supports options such as limiting the number of results and specifying a start time for the search. The "Search Recent (v1.1 Fallback)" operation first attempts to use the newer v2 API endpoint; if no results are returned and fallback is enabled, it automatically queries the v1.1 API to ensure data retrieval.

Common scenarios where this node is beneficial include:

  • Monitoring social media trends by searching for recent tweets containing specific keywords or hashtags.
  • Gathering real-time data for sentiment analysis or brand monitoring.
  • Collecting tweets for research or marketing campaigns where fallback ensures broader coverage.

Practical example: A marketer wants to track mentions of their product in the last 24 hours. They configure the node with a query for the product name, set max results to 50, specify a start time 24 hours ago, and enable fallback to maximize the chance of retrieving relevant tweets.

Properties

Name Meaning
Authentication Method of authenticating with Twitter API: "OAuth1.0a" or "Bearer Token".
Query The search query string used to find tweets matching specified keywords or phrases.
Max Results Maximum number of tweets to return, between 10 and 100.
Start Time Optional ISO 8601 formatted timestamp to specify the earliest tweet creation time to include in results.
Use Fallback Boolean flag indicating whether to use Twitter API v1.1 search as a fallback if v2 returns no results.

Output

The node outputs an array of JSON objects representing tweets retrieved from Twitter. Each item corresponds to one tweet or a batch of tweets depending on the API response.

  • For the v2 API, the output includes detailed tweet information such as author ID, public metrics (like counts), creation date, attachments, and expanded user and media fields if requested.
  • For the v1.1 fallback, the output contains tweets with extended mode enabled, including full text and entities.
  • The output is structured as JSON under the json property of each item.
  • No binary data output is produced by this operation.

Dependencies

  • Requires valid Twitter API credentials configured in n8n, either via OAuth 1.0a or Bearer Token authentication.
  • Uses Twitter API endpoints /2/tweets/search/recent for v2 and /1.1/search/tweets.json for v1.1 fallback.
  • Network connectivity to Twitter API endpoints is necessary.

Troubleshooting

  • No results returned: If the v2 API returns no tweets, ensure that the query is correctly formed and that the start time is not too restrictive. Enabling fallback can help retrieve results from the older API.
  • Authentication errors: Verify that the provided API credentials have the correct permissions and are not expired or revoked.
  • Rate limits exceeded: Twitter APIs enforce rate limits; hitting these will cause errors. Consider reducing the frequency of requests or increasing intervals.
  • Invalid date format: The Start Time must be in ISO 8601 format; incorrect formatting will cause request failures.
  • Max Results out of range: Ensure the Max Results value is between 10 and 100; values outside this range may cause errors.

Links and References

Discussion