Top 7 Tips and Tricks For Twitter API Posting

These 7 tips and tricks will help you get the most out of the Twitter API.

There are tons of tools for posting on Twitter. web app. However, if you plan to use the API to connect to social networks, you have to do it a little differently.

What is the Twitter API?

that much Twitter API You can access Twitter programmatically for Tweets, Direct Messages, Spaces, Twitter Threads, and more. There is a separate Twitter Ads API that we will not discuss in this article.

Some of the most popular use cases for the Twitter API include creating Tweets, deleting Tweets, getting a list of Tweet history, and getting analytics data about a Tweet or user.

To get started with the Twitter API, you can apply for a developer account to get your own API key, dig into the documentation for Twitter API v2, or use a social media API provider like Ayrshare.

Tip 1: Choose between Twitter API v1.1 and v2

If you are starting with a new developer account, you should start building with version 2 of the Twitter API. But some features, still missing in v2, including some Twitter data from v1.1. For example, Media Uploads, Direct Messages, Trends and Friendships are not yet available in v2. If you need an endpoint that is not yet available in v2, start with v1.1. On the other hand, in v2 you get some nice new features like voting.

You must apply for special access to use v1.1 in “User Authentication Settings” on the Twitter Developer Portal. more information about Twitter’s v2 roadmap.

Twitter API Roadmap, Mid-March 2022

Alternatively, the Ayrshare API can take full advantage of the Twitter API v.1.1 and v2 with a simpler to use API that abstracts all of this and also provides access to APIs from Facebook, Instagram, YouTube, TikTok, Linkedin, and more.

Tip 2: Upload images and videos via API

Currently only Twitter API v1.1 is allowed. upload You can attach media such as images or videos to Tweets.

Unlike some other social media APIs, Twitter doesn’t only accept URLs for media, which makes things a bit more difficult and error prone.

twitter image upload

The image should look like this: Posted As a base 64 encoded file or as a raw binary file. I’ve found that Base64 encoding is more reliable, but the media is larger and files can be larger than the size limit allowed by Twitter.

The response includes the media ID. Save this ID as you will need it to post tweets.

twitter video upload

Videos or large images should be posted as follows: chunk of bytes. There are three steps to publishing a video.

  1. Initialize the upload using the INIT command
  2. Upload each byte chunk using the APPEND command
  3. Complete the upload using the FINALIZE command

one trick The goal is to make the maximum chunk size to 1MB. Bigger things often fail on Twitter. As with image uploads, the response includes the media ID to use when posting the Tweet.

Here is an example of INIT data you can post to Node.js using a request package.

const formData = {
       command: "INIT",
       media_type: “video/mp4”,
       total_bytes: 384922834,
       media_category: "tweet_video",
     };
     const options = {
       url: "https://upload.twitter.com/1.1/media/upload.json",
       oauth: oauthCredentials,
       headers: {
         "content-type": "multipart/form-data",
       },
       formData: formData,
       redirect: 'follow'
     };
request.post(options, (err, response, body) => {...});

Be aware of “follow” redirects and content types. Both are critical to successfully uploading your media to Twitter.

Tip 3: Automated bots

In February 2022, Twitter launched a new feature called Automated Labels. This allows users to declare themselves that the content of this Twitter handle is posted through some sort of automation and is not human-authored.

There are many good use cases for automatically posting to Twitter via the API. For example, if your app automatically posts a weather forecast every hour, a museum that posts an image of a painting every day, a job site that posts every new job opening, or a data provider that posts stock prices when a new 52 weeks is up.

Example of auto-labeling for a Twitter account

Remember that even if you use this label, you still need to follow all Twitter rules, including: automation rules. Twitter takes platform manipulation very seriously and has algorithms in place to monitor all user activity. In the second half of 2020, Twitter received 4.7 million spam reports from users and challenged 143 million accounts identified as spam.

According to Twitter’s self-reporting data, it receives more than 600,000 spam reports per month.

Tip 4: Resizing images and videos and file formats

make sure you know Current Specifications for Images and Videos on twitter. The maximum file size for an image is 5 MB, for a video it is 512 MB, and the runtime is 2 minutes and 20 seconds. Twitter is grant special powers If you are an Amplify partner, you can watch larger and longer (10 minutes) videos.

The recommended size for posting one image is 1200 x 675, but the recommended size will change if you share more than one image.

The maximum resolution for a video is 1280×1024, but the recommended size varies depending on whether the video is horizontal, vertical, or square.

These specifications are important for Twitter to accept tweets you send with your media and to make your media look great on all Twitter clients.

Tip 5: Twitter thread Tweetstorm

If you are an active user on Twitter, you can see multiple Tweet threads posted by you. This is common because Twitter limits individual tweets to 280 characters, and if you have a longer post to post, splitting it into multiple tweets will create a thread.

These threads are often referred to as “Tweetstorms” and can sometimes be quite long. To help readers navigate these threads, users often have a total of 10 tweets in the thread and use a notation like 2/10 to indicate that they are reading the second tweet.

Example of a Twitter thread (Tweetstorm)

The Twitter mobile app makes it easy to create these threads by composing all your tweets at once using the “+” button on the compose screen.

Create a Twitter thread using the Twitter iOS mobile app

However, the Twitter API does not allow posting these Twitter threads directly. I need a more complex implementation that creates tweets and then responds to each in turn, tracking the number of characters per tweet and the total tweets against a counter.

an easier solution is Ayrshare Twitter Thread Poster Automatically create Tweetstorms. You can send a long set of text and a list of media assets to the API endpoint, and the system will automatically divide it by the correct number of tweets, add a number like 2/10, and add the media asset to the correct tweet.

Tip 6: Follow the rules for how often unrelated people mention you.

Be very careful when referring to other users in Tweets you send through the API. Here quote from twitter:

“Automating these actions to reach a large number of users in an unsolicited way is an abuse of functionality and is not allowed. For example, auto-replying to Tweets by keyword searches alone is not allowed. Spam mentions and replies. Redemption or duplicate use may result in actions such as removal of Tweets from searches or suspension of the app or account.

Source: Twitter

Experience has shown that Twitter is very serious about this and often suspends accounts without warning if you break this rule.

The correct way to use mentions in tweets is

  1. Limit to one mention per tweet.
  2. Only mention users who have previously interacted with your user account. For example, if they mention your Twitter handle in their tweets.
  3. Limit mentions. Even if other users mention you, try to minimize the amount and frequency of mentions.
  4. Ask for permission to refer to anyone who has never mentioned you.
  5. When a user requests to opt out of your service, respect it and stop commenting. You can easily opt out of filing a complaint directly with Twitter.

Since this logic is not easy to implement, Ayrshare provides an additional service to the Twitter API to help customers comply with these rules on Twitter and protect their accounts from suspension.

Tip 7: Do not post duplicate content to your account or multiple accounts.

All posts should be as unique as possible. Twitter users don’t want to see duplicate content because it looks like spam.

Duplicate posts have low visibility and engagement, and Twitter will suspend accounts with too many duplicate or similar posts. Don’t do that, as posting duplicate content to multiple Twitter accounts will result in the same thing.

conclusion

Twitter’s API is a powerful tool for developers to engage with social media networks on behalf of their users. Over the past few years, Twitter has put more effort into releasing new features and providing access to more data to build on. All Twitter developers should follow these tips to get the most out of the Twitter API.

Source

Explore additional categories

Explore Other Classes