curl -X POST "https://api.x.com/2/tweets" \ -H "Authorization: Bearer $USER_ACCESS_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "text": "Photo of the day!", "media": { "media_ids": ["1234567890123456789"] } }'
from xdk import Clientfrom xdk.oauth1_auth import OAuth1oauth1 = OAuth1( api_key="YOUR_API_KEY", api_secret="YOUR_API_SECRET", access_token="YOUR_ACCESS_TOKEN", access_token_secret="YOUR_ACCESS_TOKEN_SECRET")client = Client(auth=oauth1)# Post with mediaresponse = client.posts.create( text="Photo of the day!", media={"media_ids": ["1234567890123456789"]})print(f"Created Post with media: {response.data.id}")
import { Client, OAuth1 } from "@xdevplatform/xdk";const oauth1 = new OAuth1({ apiKey: "YOUR_API_KEY", apiSecret: "YOUR_API_SECRET", accessToken: "YOUR_ACCESS_TOKEN", accessTokenSecret: "YOUR_ACCESS_TOKEN_SECRET",});const client = new Client({ oauth1 });// Post with mediaconst response = await client.posts.create({ text: "Photo of the day!", media: { mediaIds: ["1234567890123456789"] },});console.log(`Created Post with media: ${response.data?.id}`);
from xdk import Clientfrom xdk.oauth1_auth import OAuth1oauth1 = OAuth1( api_key="YOUR_API_KEY", api_secret="YOUR_API_SECRET", access_token="YOUR_ACCESS_TOKEN", access_token_secret="YOUR_ACCESS_TOKEN_SECRET")client = Client(auth=oauth1)# Post with pollresponse = client.posts.create( text="What is your favorite color?", poll={"options": ["Red", "Blue", "Green", "Yellow"], "duration_minutes": 1440})print(f"Created poll: {response.data.id}")
import { Client, OAuth1 } from "@xdevplatform/xdk";const oauth1 = new OAuth1({ apiKey: "YOUR_API_KEY", apiSecret: "YOUR_API_SECRET", accessToken: "YOUR_ACCESS_TOKEN", accessTokenSecret: "YOUR_ACCESS_TOKEN_SECRET",});const client = new Client({ oauth1 });// Post with pollconst response = await client.posts.create({ text: "What is your favorite color?", poll: { options: ["Red", "Blue", "Green", "Yellow"], durationMinutes: 1440 },});console.log(`Created poll: ${response.data?.id}`);
Post with paid partnership
Use the paid_partnership field to indicate that this Post is a paid partnership (i.e., the author is disclosing it contains paid promotion). When set to true, the Post will be labeled as a paid promotion.
cURL
curl -X POST "https://api.x.com/2/tweets" \ -H "Authorization: Bearer $USER_ACCESS_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "text": "Excited to partner with Acme on their latest launch!", "paid_partnership": true }'
from xdk import Clientfrom xdk.oauth1_auth import OAuth1oauth1 = OAuth1( api_key="YOUR_API_KEY", api_secret="YOUR_API_SECRET", access_token="YOUR_ACCESS_TOKEN", access_token_secret="YOUR_ACCESS_TOKEN_SECRET")client = Client(auth=oauth1)# Post with paid partnershipresponse = client.posts.create( text="Excited to partner with Acme on their latest launch!", paid_partnership=True)print(f"Created paid partnership post: {response.data.id}")
import { Client, OAuth1 } from "@xdevplatform/xdk";const oauth1 = new OAuth1({ apiKey: "YOUR_API_KEY", apiSecret: "YOUR_API_SECRET", accessToken: "YOUR_ACCESS_TOKEN", accessTokenSecret: "YOUR_ACCESS_TOKEN_SECRET",});const client = new Client({ oauth1 });// Post with paid partnershipconst response = await client.posts.create({ text: "Excited to partner with Acme on their latest launch!", paidPartnership: true,});console.log(`Created paid partnership post: ${response.data?.id}`);
Delete a Post
1
Get the Post ID
You need the ID of the Post you want to delete. This is returned when you create a Post.