---
title: "X (formerly Twitter)"
description: "Send and delete tweets."
enableComments: true
author: "Steven Lynn"
github_username: "stvlynn"
x_username: "Stv_Lynn"
---

⬇️ Try it out before reading
<Callout title="How to use">Enter the topic you want to tweet about, and the workflow will automatically post a tweet using a test account.</Callout>

<iframe
 src="https://instance.hellodify.com/chatbot/PiSEbSPbx294M0UQ"
 style={{
   width: '100%',
   minHeight: '500px'
 }}
 frameBorder="0"
 allow="microphone">
</iframe>

---

<Cards>
  <Card 
    icon={<i className="ri-github-fill" />} 
    href="https://github.com/stvlynn/x-dify-plugin" 
    title="GitHub"
  >
  <p>See the repository on GitHub</p>
  </Card>
  <Card 
    icon={<i className="ri-store-2-line" />} 
    href="https://marketplace.dify.ai/plugins/stvlynn/x" 
    title="Dify Marketplace"
  >
  <p>Install from Dify Marketplace</p>
  </Card>
</Cards>

---

## Description

This plugin allows you to interact with the X (formerly Twitter) platform through their official API. 

It provides tools to send and delete tweets.

## Features

- **Post Tweet**: Send tweets to your X account and receive the tweet ID in response
- **Delete Tweet**: Delete tweets by their ID
- **Post Media Tweet**: Send tweets with media attachments (images or videos)

## Setup

1. Create a developer account at [X Developer Portal](https://developer.twitter.com/)
2. Create a project and app to obtain your API keys:
   - Go to the [Developer Portal Dashboard](https://developer.twitter.com/en/portal/dashboard)
   - Click "Create Project" and follow the steps
   ![image.png](https://s2.loli.net/2025/05/15/TXPEe3tQmszhSfK.png)
   - Within your project, create an app to get your API keys and tokens
   - Navigate to the "Keys and tokens" section to find your Consumer Keys (API Key and Secret)
   ![image.png](https://s2.loli.net/2025/05/15/u8RxPvQoYVfDksr.png)
3. Set up authentication:
   - Clone this repository to your local machine:
     ```
     git clone https://github.com/stvlynn/X-Dify-Plugin.git
     cd X-Dify-Plugin
     ```
   - Edit the `auth.py` file and fill in your Consumer Key and Secret
   ![image.png](https://s2.loli.net/2025/05/15/XGa6fQjeI7HTsck.png)
   - Run the authentication script:
     ```
     python auth.py
     ```
   - The script will provide an authorization URL. Open it in your browser
   - Authorize your application and enter the verification code when prompted
   ![image.png](https://s2.loli.net/2025/05/15/UJPdYHaqThkAQnR.png)
   - The script will output your ACCESS_TOKEN and ACCESS_TOKEN_SECRET
4. Configure the plugin in Dify:
   - Install the X Plugin from the Dify Marketplace
   - In the plugin settings, enter the following credentials:
     - **API Key**: Your X API Key (Consumer Key)
     - **API Secret**: Your X API Secret (Consumer Secret)
     - **Access Token**: OAuth 1.0a Access Token generated from auth.py
     - **Access Token Secret**: OAuth 1.0a Access Token Secret generated from auth.py

### Authentication Notes

- All credentials are stored securely and used only for authenticating with the X API
- You need Read and Write permissions for your app to post and delete tweets
- To verify your credentials are working, the plugin will make a test API call to the X API

### Usage

#### Posting a Tweet

![image.png](https://s2.loli.net/2025/05/15/QgHeYb6BGDUFipL.png)

```json
{
  "text": "Your tweet content here"
}
```

Response:
```json
{
  "status": "success",
  "tweet_id": "1234567890123456789",
  "text": "Your tweet content here",
  "message": "Tweet published successfully with ID: 1234567890123456789"
}
```

#### Deleting a Tweet

![image.png](https://s2.loli.net/2025/05/15/u3vP9NWbkflzH8x.png)

```json
{
  "tweet_id": "1234567890123456789"
}
```

Response:
```json
{
  "status": "success",
  "message": "Tweet with ID 1234567890123456789 deleted successfully"
}
```

#### Posting a Media Tweet

This action allows you to upload and attach media (images or videos) to your tweets.

![image.png](https://s2.loli.net/2025/05/15/dgBr9VzOMQota6y.png)

Parameters:
- `text`: The text content of your tweet (max 280 characters)
- `media`: The media file to attach (image or video)

Supported media formats:
- Images: JPEG, PNG, GIF
- Videos: MP4 (H.264 codec recommended)

Note: Videos may take longer to process on X platform before the tweet is published.

```json
{
  "text": "Check out this awesome media!",
  "media": [Binary file data]
}
```

Response:
```json
{
  "status": "success",
  "tweet_id": "1234567890123456789",
  "text": "Check out this awesome media!",
  "media_id": "9876543210987654321",
  "message": "Tweet with media published successfully with ID: 1234567890123456789"
}
```
