Automate YouTube to X Posts Using n8n and OpenAI

Save time promoting your latest YouTube videos by automating engaging post creation and posting to X (Twitter) using n8n. This workflow fetches your newest videos, drafts witty posts under 220 characters, and updates Google Sheets with post details.
twitter
youTube
googleSheets
+12
Workflow Identifier: 1683
NODES in Use: twitter, stickyNote, youTube, toolCalculator, toolWikipedia, scheduleTrigger, googleSheets, manualTrigger, discord, removeDuplicates, openAi, set, if, slack, gmail

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

Visit through Desktop for Best experience

What This Automation Does

This workflow finds newest YouTube videos from one channel and makes posts for X automatically.
It stops repeated posts and makes sure tweets are short enough.
The posts get pasted on X and all info is saved in Google Sheets.
This saves many hours of work and stops mistakes like too long tweets or missing tracking.

The process uses YouTube to get videos, OpenAI to write tweets under 220 characters with video links, then posts them on X with OAuth2 access.
It also updates a Google Sheet to log what was posted and when.


Tools and Services Used

  • YouTube Data API: Fetches new videos from a channel.
  • OpenAI GPT-4o-mini: Writes catchy X posts under character limits.
  • X (Twitter) API via OAuth2: Posts tweets automatically.
  • Google Sheets API: Logs posts with date, content, and status.
  • n8n Automation Platform: Connects all nodes and runs flow.

Input, Processing, and Output

Inputs

  • Channel ID for YouTube channel.
  • OAuth2 credentials for YouTube, X, Google Sheets.
  • OpenAI API Key.

Processing Steps

  • Get videos published in last 20 hours from YouTube.
  • Extract video IDs.
  • Remove duplicates already posted.
  • Check if any videos left.
  • Use OpenAI to write tweet with video title, description, and video URL.
  • Check tweet length; rewrite if too long.
  • Prepare data for Google Sheets logging.
  • Post tweet on X using OAuth2.
  • Update Google Sheets record with post URL and status.

Outputs

  • Published tweet with latest video link.
  • Complete log entry in Google Sheets.

Who Should Use This Workflow

Anyone who uploads videos on YouTube and wants quick posts on X without extra work.
Great for content creators, marketers, and small businesses who want to save time.
No deep coding required; only basic n8n and credential setup.
Users with multiple channels or social accounts can customize as needed.


Beginner Step-by-Step: How to Use This Workflow in n8n

Import the Workflow

  1. Download the workflow JSON file using the Download button on this page.
  2. Open n8n editor already logged in.
  3. Click Import > Import from File, select the downloaded JSON.

Configure Credentials and Parameters

  1. Add or update OAuth2 credentials for YouTube, X, Google Sheets in n8n credential manager.
  2. Update YouTube node channelId if needed.
  3. In OpenAI nodes, confirm the prompt uses:
    Write an engaging post about my latest YouTube video for X (Twitter) of no more than 220 characters in length. Link to the video at https://youtu.be/{{ videoId }} use this title and description: {{ title }} {{ description }}. If no description, guess the context. The link must be at the end.
    
  4. Update Google Sheets node with correct spreadsheet ID and sheet name.

Test and Activate

  1. Run the workflow manually to verify video fetching, post generation, and logging.
  2. Ensure tweets appear on the X account and Google Sheets updates.
  3. Activate the schedule node to run every 2 hours or desired interval for production.

If you use self-host n8n, refer to self-host n8n for server setup and secure deployment.


Important Expressions and Prompts

Use this JavaScript expression to get videos from last 20 hours in YouTube node’s publishedAfter field:

=< new Date(new Date().getTime() - 1200 * 60000).toISOString() 

Extract video ID in Set node using:

{{ $json.id.videoId }} 

OpenAI prompt for writing X post:

Write an engaging post about my latest YouTube video for X (Twitter) of no more than 220 characters in length. Link to the video at https://youtu.be/{{ videoId }} use this title and description: {{ title }} {{ description }}. If no description, guess the context. The link must be at the end.


Common Problems and How to Fix

  • No videos fetched from YouTube node.
    Cause: Wrong channel ID or missing YouTube Data API scope.
    Fix: Check channel ID in YouTube advanced settings. Verify OAuth2 OAuth scopes include YouTube Data API.
  • Posts fail to publish on X due to OAuth2 error.
    Cause: Expired or lacking Twitter permissions.
    Fix: Reauthenticate Twitter OAuth2 in n8n credentials and check app permissions.
  • OpenAI returns unrelated or short text.
    Cause: Poor prompt or missing input data.
    Fix: Use example prompt exactly and confirm title and description inputs.

Customization Ideas

  • Switch Twitter node to another social node such as Mastodon.
  • Add HTTP Request node to shorten YouTube URL before posting.
  • Include hashtags or mentions by updating OpenAI prompt or Set node.
  • Enable scheduled runs with the existing schedule node.
  • Extend to post video thumbnails alongside tweets or save them in Google Sheets.

Summary

✓ Finds newest YouTube videos automatically.
✓ Writes engaging, tweet-ready messages using OpenAI.
✓ Limits tweet length to platform max.
✓ Posts to X with OAuth2 permissions.
✓ Logs posts details to Google Sheets.
✓ Saves hours of repetitive manual work.
✓ Keeps a clean, updated content record.


Frequently Asked Questions

The YouTube node uses your channel ID and a date filter to get videos published in the last 20 hours.
The workflow checks tweet length automatically and uses another OpenAI node to rewrite tweets if over 220 characters.
Update and reauthenticate the Twitter OAuth2 credentials in n8n and verify permissions in the Twitter developer portal.
Yes, by replacing the Twitter node with another social posting node such as Mastodon node in n8n.

Promoted by BULDRR AI

Related Workflows

Automate Viral UGC Video Creation Using n8n + Degaus (Beginner-Friendly Guide)

Learn how to automate viral UGC video creation using n8n, AI prompts, and Degaus. This beginner-friendly guide shows how to import, configure, and run the workflow without technical complexity.
Form Trigger
Google Sheets
Gmail
+37
Free

AI SEO Blog Writer Automation Workflows in n8n

A complete beginner guide to building an AI SEO blog writer automation using n8n.
AI Agent
Google Sheets
httpRequest
+5
Free

Automate CrowdStrike Alerts with VirusTotal, Jira & Slack

This workflow automates processing of CrowdStrike detections by enriching threat data via VirusTotal, creating Jira tickets for incident tracking, and notifying teams on Slack for quick response. Save hours daily by transforming complex threat data into actionable alerts effortlessly.
scheduleTrigger
httpRequest
jira
+5
Free

Automate Telegram Invoices to Notion with AI Summaries & Reports

Save hours on financial tracking by automating invoice extraction from Telegram photos to Notion using Google Gemini AI. This workflow extracts data, records transactions, and generates detailed spending reports with charts sent on schedule via Telegram.
lmChatGoogleGemini
telegramTrigger
notion
+9
Free

Automate Email Replies with n8n and AI-Powered Summarization

Save hours managing your inbox with this n8n workflow that uses IMAP email triggers, AI summarization, and vector search to draft concise replies requiring minimal review. Automate business email processing efficiently with AI guidance and Gmail integration.
emailReadImap
vectorStoreQdrant
emailSend
+12
Free

Automate Email Campaigns Using n8n with Gmail & Google Sheets

This n8n workflow automates personalized email outreach campaigns by integrating Gmail and Google Sheets, saving hours of manual follow-up work and reducing errors in email sequences. It ensures timely follow-ups based on previous email interactions, optimizing communication efficiency.
googleSheets
gmail
code
+5
Free