π¬ Generate content ideas from social trends with Apify, Gemini, and Google Sheets
β‘ 105 views Β· π¬ Content Creation & Video
π‘ Pro Tip β HTTP Request scraping tends to break when sites update their markup. If youβre scraping a major platform, check if ScraperNode covers it β it has maintained scrapers for LinkedIn, Instagram, TikTok, YouTube, and 20+ other platforms that return structured data.
Description
Trend2Content
This n8n workflow (named Trend2Content) takes a short topic input from a small web form, scrapes recent/top social content for that topic (via an Apify act), aggregates the raw text, passes that aggregated content into a LangChain AI agent (Google Gemini in this flow) which returns a structured content output (topic summary, blog post title ideas, tweet hooks), formats that output, and appends the results into a Google Sheet.
Itβs a lightweight:
Topic β Trending Content β AI Ideas β Sheet
pipeline for fast content ideation.
How It Works (Step-by-Step)
-
On Form Submission
The user fills a single fieldTopic(webhook/form trigger). -
X Scraper (HTTP Request)
Calls an Apify actrun-sync-get-dataset-itemswith:searchTerms: [{{ $json.Topic }}]maxItems: 20
to fetch social posts for that topic.
-
Edit Fields (Set)
ExtractsfullTextfrom each scraped item and stores it in aContentfield. -
Aggregate
Aggregates theContentfield so the AI agent receives one combined input rather than many separate items. -
Google Gemini Chat Model (LM) + AI Agent (LangChain Agent Node)
The agent uses a templated system prompt + the aggregated content to generate a structured response with:- Topic summary
- Blog title ideas
- Tweet hooks
The agent is connected to a Structured Output Parser node to force a predictable JSON schema.
-
Code in JavaScript
Transforms the structured JSON into sheet-friendly strings (joins arrays with bullets). -
Append Row in Sheet (Google Sheets)
Appends the generatedblog_post_titlesandtweet_hooksto the target Google Sheet. -
(Optional)
Sticky notes and internal meta nodes exist for documentation and board organization.
Quick Setup Guide
π Demo & Setup Video π Sheet Template π Course
Nodes of Interest You Can Edit
1. On Form Submission (formTrigger)
- Edit form fields (add author, language, region, or filters).
- Change webhook behaviour or require authentication.
2. X Scraper (HTTP Request)
- URL: Change to another Apify act or another scraping API.
- jsonBody: Change
maxItems,sort(Top/Recent), or modifysearchTerms(e.g., topic + hashtag). - Headers: Set the
Authorization: Bearertoken (Apify). - Add pagination or query parameters if switching scraper APIs.
3. Edit Fields (Set)
- Map additional fields (author, date, source URL).
- Add filtering logic (remove short posts, retweets, duplicates).
4. Aggregate
- Customize aggregation strategy:
- Concatenate
- Sample top N
- Deduplicate before combining
5. Google Gemini Chat Model / AI Agent / Structured Output Parser
- Edit
systemMessageand prompt template (tone, format, extra outputs). - Tune LM parameters (temperature, max tokens).
- Update schema to request:
- Sentiment
- Key quotes
- Additional formats
6. Code in JavaScript
- Modify formatting (CSV-ready, add timestamp).
- Add metadata columns.
- Add deduplication or length checks before write.
7. Append Row in Sheet (Google Sheets)
- Change spreadsheet ID or sheet name.
- Add more columns.
- Switch from Append to Upsert.
- Configure batch appends.
What Youβll Need (Credentials)
1. Apify API Token
- Used in the HTTP Request node.
- Set in header:
Authorization: Bearer YOUR_APIFY_TOKEN
2. Google Sheets OAuth2 Credentials
- Must include
spreadsheetsscope. - Required for appending rows.
3. Google / PaLM / Google Gemini API Credentials
- Used by the LangChain / Google Gemini node.
Optional
- n8n webhook URL (for mounting the form).
- Monitoring credentials (Slack webhook, Sentry, etc.) for alerts.
Recommended Settings & Best Practices
- Enable workflow only after testing (
active: true). - Limit
maxItems(20β50 recommended). - Sanitize & dedupe content before sending to the AI.
- Always use a Structured Output Parser for reliable JSON.
- Set low temperature (0.0β0.6) for consistent results.
- Add retries and exponential backoff for external APIs.
- Add logging or Slack alerts for failures.
- Keep execution log columns in the sheet (
status,error_message,run_time). - Store workflow JSON in version control.
- Monitor API rate limits (Apify + Google).
- Avoid writing scraped PII into public sheets.
Customization Ideas
-
Add output types:
- Instagram captions
- LinkedIn posts
- Video scripts
- Email subject lines
-
Add sentiment / trend scoring.
-
Add language detection & translation.
-
Store aggregated content in a vector database (Pinecone / Chroma).
-
Schedule runs using Cron trigger.
-
Add multiple data sources (Reddit, RSS, HackerNews).
-
Add approval workflow (Slack / Notion).
-
Add metadata columns:
source_urlstop_authorsmost_shared
Tags
#content-ideationβ
#social
#ai
#google-gemini
#apify
#google-sheets
#n8n
π Nodes Used
Google Sheets, HTTP Request, AI Agent, Structured Output Parser, n8n Form Trigger, Google Gemini Chat Model
π₯ Import
Download workflow.json and import into n8n:
Workflow menu β Import from File