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
Automate YouTube to X with n8n and OpenAI

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

Learn how to Build this Workflow with AI:

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


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.


Automate YouTube to X with n8n and OpenAI

Visit through Desktop to Interact with the Workflow.

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 Twist Channel Creation and Messaging with n8n

This workflow automates creating and updating a channel in Twist and sending a personalized message to specific users. It eliminates manual setup errors and saves time managing Twist communications.

Automate Ideogram Image Generation with Google Sheets & Gmail

This workflow automates graphic design image generation via Ideogram AI, storing image data in Google Sheets and Google Drive, with email alerts via Gmail. It saves designers hours by automating image creation, remixing, review, and record-keeping.

Automate IT Support with Slack and OpenAI in n8n

Streamline IT support by automating Slack message handling using n8n and OpenAI. This workflow handles Slack DMs, filters bots, queries a Confluence knowledge base, and delivers AI-generated responses, improving support efficiency and response time.

Automate Crypto Analysis with CoinMarketCap & n8n AI Agent

Discover how this unique n8n workflow leverages CoinMarketCap’s multi-agent AI to deliver precise, real-time cryptocurrency insights directly via Telegram. Manage crypto data analysis efficiently with automated multi-source API integration.

Automate Gumroad to Beehiiv Subscriber Sync with n8n

Learn how to automatically add new Gumroad sales customers as Beehiiv newsletter subscribers using n8n automation. This workflow saves time by syncing sales data to Google Sheets CRM and notifying your Telegram channel instantly.

Generate On-Brand Blog Articles Using n8n and OpenAI

This workflow automates the creation of on-brand blog articles by analyzing existing company content using n8n and OpenAI. It extracts article structures and brand voice to produce consistent draft articles, saving significant content creation time.
1:1 Free Strategy Session
Your competitors are already automating. Are you still paying for it manually?

Do you want to adopt AI Automation?

Every hour your team does repetitive work, you're burning real money.
While you wait, faster businesses are cutting costs and moving quicker.
AI and automations aren't the future anymore — they're the present.

Book a live 1-on-1 session where we show you exactly which of your daily tasks can be automated — and what it’s costing you not to.