X (Twitter) keyword posts to Google Sheets with n8n
Public X posts that mention your keywords or hashtags land in a sheet with the matching keyword, the author's handle, the post text, the time, and the like, reply, repost and view counts, plus the link. Each post is written once, so the sheet grows into a searchable log of the conversation.
Put your keywords, hashtags or full X search queries in keywords in the request body and keep the search type on Latest. Each run reads up to 50 posts. Filters for replies, reposts, language and verified authors sit in the same body.
Built-in nodes only Imports on n8n Cloud and self-hosted n8n 1.80 or later, no community nodes. 11 of 11 checks pass; validated, not executed.
- Source
- X (Twitter)
- Destination
- Google Sheets
- Store price
- $0.99 per 1,000 results (pay per event)
- Cost on the Free plan
- about $0.45 a run (start $0.40 + up to 50 results), about $13.48 a month daily, plus platform usage
- Data checked
- 2026-11-12
Method
-
Get an Apify token
Sign in to Apify and copy a personal API token from Console: Settings, API and integrations. The workflow keeps it in an n8n credential, never in the file.
-
Import the workflow
In n8n choose Workflows, Import from file, or paste the JSON onto an empty canvas.
- Run by hand
- Every day
- Run Apify Actor
- Only records not sent before
- Keep main fields
- Send to Google Sheets
n8n workflowx-posts-to-google-sheets.n8n.json
Show the file (207 lines)
{ "name": "X (Twitter) keyword posts to Google Sheets", "nodes": [ { "id": "02345e26-5a9c-4329-a567-aefc3dfa9573", "name": "Run by hand", "type": "n8n-nodes-base.manualTrigger", "typeVersion": 1, "position": [ 0, 0 ], "parameters": {} }, { "id": "728b3c06-f4f5-4be7-a201-77065d16f5b3", "name": "Every day", "type": "n8n-nodes-base.scheduleTrigger", "typeVersion": 1.2, "position": [ 0, 200 ], "parameters": { "rule": { "interval": [ { "triggerAtHour": 8 } ] } }, "notes": "Activate the workflow to run on this schedule." }, { "id": "b164500a-0cc1-4a50-a6c2-565dd497e48f", "name": "Run Apify Actor", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 260, 100 ], "parameters": { "method": "POST", "url": "https://api.apify.com/v2/actors/nimbryxo-studio~x-twitter-keyword-and-hashtag-tweet-search/run-sync-get-dataset-items", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "sendBody": true, "specifyBody": "json", "jsonBody": "{\n \"keywords\": [\n \"n8n\"\n ],\n \"maxTweets\": 50,\n \"searchType\": \"Latest\",\n \"language\": \"Any language\",\n \"excludeRetweets\": false,\n \"excludeReplies\": false,\n \"onlyVerifiedUsers\": false,\n \"onlyImages\": false,\n \"onlyVideos\": false,\n \"onlyQuotes\": false,\n \"matchMode\": \"all\",\n \"onlyNew\": false,\n \"monitoringEnabled\": false\n}", "options": { "timeout": 310000 } }, "notes": "Actor: nimbryxo-studio/x-twitter-keyword-and-hashtag-tweet-search. Select a Header Auth credential: name Authorization, value Bearer + your Apify token. Edit the JSON body to change the input.", "notesInFlow": false }, { "id": "0231d4c6-5a35-4d6d-a9ef-10683b36b073", "name": "Only records not sent before", "type": "n8n-nodes-base.removeDuplicates", "typeVersion": 2, "position": [ 500, 100 ], "parameters": { "operation": "removeItemsSeenInPreviousExecutions", "logic": "removeItemsWithAlreadySeenKeyValues", "dedupeValue": "={{ $json.url }}", "options": { "scope": "node", "historySize": 10000 } }, "notes": "Remembers each url it has passed on (up to 10,000) across runs, so a record is sent once. Needs n8n 1.64 or later." }, { "id": "21ebddce-5eb1-4c8f-a56f-ef5e7437e4fb", "name": "Keep main fields", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 740, 100 ], "parameters": { "jsCode": "// Keeps the Actor's main fields as flat, spreadsheet-safe values.\nconst columns = [\"searchTerm\",\"author.username\",\"text\",\"createdAt\",\"likeCount\",\"replyCount\",\"retweetCount\",\"viewCount\",\"url\"];\n// A dotted name such as author.name reads the nested value.\nconst read = (obj, key) => (key in obj ? obj[key] : key.split('.').reduce((v, part) => (v && typeof v === 'object' ? v[part] : undefined), obj));\nreturn $input.all().map((item) => {\n const row = {};\n const present = columns.filter((key) => read(item.json, key) !== undefined);\n // A record shaped differently from the published schema keeps its own fields rather than arriving blank.\n for (const key of present.length >= 2 ? present : Object.keys(item.json)) {\n const value = read(item.json, key);\n row[key] = value === null || value === undefined ? '' : typeof value === 'object' ? JSON.stringify(value) : value;\n }\n return { json: row };\n});" } }, { "id": "f99b9d3e-bcef-4b03-ad1b-dfc607b686db", "name": "Send to Google Sheets", "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.5, "position": [ 980, 100 ], "parameters": { "operation": "append", "documentId": { "__rl": true, "value": "", "mode": "list", "cachedResultName": "" }, "sheetName": { "__rl": true, "value": "Sheet1", "mode": "name" }, "columns": { "mappingMode": "autoMapInputData", "value": {}, "matchingColumns": [], "schema": [] }, "options": {} }, "notes": "Pick your spreadsheet. The tab is set to Sheet1; change it if yours has another name. Add these headers in row 1: searchTerm, author.username, text, createdAt, likeCount, replyCount, retweetCount, viewCount, url." }, { "id": "b619d3b6-0112-411f-a056-b5fa422feb13", "name": "Setup", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 0, -370 ], "parameters": { "content": "## X/Twitter Keyword & Hashtag Tweet Search\n\nSource: [nimbryxo-studio/x-twitter-keyword-and-hashtag-tweet-search](https://apify.com/nimbryxo-studio/x-twitter-keyword-and-hashtag-tweet-search) on Apify.\n\n1. In **Run Apify Actor**, create a Header Auth credential: name `Authorization`, value `Bearer YOUR_APIFY_TOKEN` with your token.\n2. Open **Send to Google Sheets** and connect your Google Sheets account.\n3. Edit the JSON body of **Run Apify Actor** to change the input.\n\nGenerated by recipeforagents.com. Validated, not executed: runs are billed to your Apify account.", "height": 340, "width": 460, "color": 6 } } ], "connections": { "Run by hand": { "main": [ [ { "node": "Run Apify Actor", "type": "main", "index": 0 } ] ] }, "Every day": { "main": [ [ { "node": "Run Apify Actor", "type": "main", "index": 0 } ] ] }, "Run Apify Actor": { "main": [ [ { "node": "Only records not sent before", "type": "main", "index": 0 } ] ] }, "Only records not sent before": { "main": [ [ { "node": "Keep main fields", "type": "main", "index": 0 } ] ] }, "Keep main fields": { "main": [ [ { "node": "Send to Google Sheets", "type": "main", "index": 0 } ] ] } }, "pinData": {}, "active": false, "settings": { "executionOrder": "v1" }, "meta": { "templateCredsSetupCompleted": false }, "tags": [] }Validated, not executed: 11 of 11 checks pass
- It has a nodes array and a connections object
- Every node has a name, type, typeVersion, position and parameters
- Node names are unique
- Every node type is a known n8n core node (or the Apify node)
- Every node uses a typeVersion that n8n ships
- Every connection points at an existing node
- At least one trigger starts the workflow
- Every working node is reachable from a trigger
- Apify calls use POST and a credential for the token
- Actor input matches the Actor's published input schema
- No token or credential value is embedded
-
Add the Apify credential
Open Run Apify Actor. Under Credential, create a Header Auth credential with the name
Authorizationand the valueBearer, a space and your token. -
Set the input
The request body holds the Actor input: the Actor's Store prefill with keywords, searchType, maxTweets set for this recipe. Change keywords and searchType to your own.
{ "keywords": [ "n8n" ], "maxTweets": 50, "searchType": "Latest", "language": "Any language", "excludeRetweets": false, "excludeReplies": false, "onlyVerifiedUsers": false, "onlyImages": false, "onlyVideos": false, "onlyQuotes": false, "matchMode": "all", "onlyNew": false, "monitoringEnabled": false }Every input field is documented on the X/Twitter Keyword & Hashtag Tweet Search page.
-
Only new records go through
The Only records not sent before node (n8n's Remove Duplicates, set to remove items processed in previous executions) remembers each
urlit has passed on, so a record reaches Google Sheets once even when the next run returns it again. It needs n8n 1.64 or later; clear its history from the node to resend everything. -
Connect Google Sheets
Open Send to Google Sheets, select your Google credential, then pick the spreadsheet from the list. The tab is set to Sheet1; change it if yours has another name. Put these headers in row 1 so the columns map automatically: searchTerm, author.username, text, createdAt, likeCount, replyCount, retweetCount, viewCount, url.
-
Run once, then turn it on
Click Execute workflow and check the first records in Google Sheets. When they look right, activate the workflow so the daily trigger runs it at 08:00 in your instance's timezone.
What lands in Google Sheets
The fields this workflow sends, filled from the example record in the Actor's own README (published by the Actor, not a run of ours).
| Field | Example value |
|---|---|
searchTerm | buildinpublic |
author.username | makerjane |
text | Just shipped a new feature after three weeks of testing. Feels good. #buildinpublic |
createdAt | 2026-06-02T09:15:00+00:00 |
likeCount | 1870 |
replyCount | 34 |
retweetCount | 112 |
viewCount | 54300 |
url | https://x.com/i/status/1923456789012345678 |
Where it breaks
- Engagement counts are taken when the post is first written and are not updated later.
- The search sees what X shows to logged-out readers, which can leave out some replies and protected accounts.
- Very broad keywords can return more posts per day than one run reads; raise maxTweets or narrow the search.
- The workflow uses Apify's synchronous endpoint, which waits up to 300 seconds. Bigger runs answer HTTP 408: lower the limit or switch to an asynchronous run.
- Each run is billed to your Apify account at the Store price ($0.99 per 1,000 results (pay per event)).
Bigger runs: the long-run workflow starts the run, waits for it and reads the dataset, so it never hits the 300-second limit.
If the workflow fails
Why does the workflow or script stop with HTTP 408?
The synchronous endpoint waits at most 300 seconds. After that it answers 408 while the run keeps going in Apify. Lower the result limit, or start the run asynchronously, wait for it to finish and then read its dataset.
Source: Apify API: run Actor synchronously and get dataset items
What do 400, 401, 402 and 403 from the Apify API mean?
Read error.type in the response body. 400 is invalid Actor input. 401 (user-or-token-not-found) means a token reached Apify but it is wrong or revoked. 402 with x402-payment-required means no token reached Apify at all: the n8n credential or the Authorization: Bearer header is missing, and Apify is offering its pay-per-run x402 route for agents instead; any other 402 is an exhausted usage limit on the account that pays for the run. 403 is a token without permission for that Actor or storage.
Source: Apify API: authentication; Apify documentation: agentic payments with x402; Apify API: run Actor synchronously and get dataset items
n8n says Install this node to use it after import. Why?
The workflow names a node or node version your instance does not have, usually a community node. The workflows here use only built-in nodes at versions n8n has shipped since 1.80, so they import on n8n Cloud and older self-hosted instances without community nodes.
Why does the HTTP Request node time out before Apify answers?
Set the node's Timeout option to at least 300000 ms so n8n waits as long as Apify's synchronous endpoint. The workflows here already set 310000. A failure at exactly 30 seconds points to a proxy in front of n8n.
Same data in an agent
Want Claude, Cursor or ChatGPT to call the Actor directly instead of on a schedule? The X/Twitter Keyword & Hashtag Tweet Search page has MCP configs for eight clients and a SKILL.md. The X (Twitter) MCP server bundles every X (Twitter) Actor in one URL.
Questions
Can I follow a brand and its hashtag together?
Yes. Add both to the keywords list; the keyword column shows which one found each post.
How are repeats avoided?
The workflow remembers each post link it has written and skips it on later runs.
More recipes
Google Maps leads to Google Sheets
Pull local business leads from Google Maps into a Google Sheet on a schedule, with phone, website, rating…
Google MapsGoogle SheetsReddit posts to Google Sheets
Collect public posts and comments from a subreddit into a Sheet for research, with duplicate protection and…
RedditGoogle SheetsLinkedIn jobs to Google Sheets
Export public job postings into a Sheet so a recruiter or researcher can filter by role, company and location.
LinkedIn JobsGoogle SheetsTikTok hashtag trends to Google Sheets
Log the view and video counts of the TikTok hashtags you follow in a Google Sheet every day, so you can…
TikTokGoogle SheetsInstagram posts to Google Sheets
Log the latest posts of the Instagram profiles you track in a Google Sheet, with captions, likes, comments…
InstagramGoogle SheetsYouTube comments to Google Sheets
Export the comments and replies of YouTube videos to a Google Sheet, newest first, with likes and author…
YouTubeGoogle Sheets