Plugins
Templates

Advanced Twitter API

Link to plugin page: https://zeroqode.com/plugin/advanced-twitter-api-1580388207316x240833466550325570

Introduction

Many endpoints on the Twitter developer platform use the OAuth 1.0a method to act, or make API requests, on behalf of a Twitter account. For example, if you have a Twitter developer app, you can make API requests on behalf of any Twitter account as long as that user authenticates your app.

The plugin can do the following actions:

1. post a tweet; 2. delete a tweet; 3. retweet or cancel a retweet; 4. like a tweet; 5. upload a timeline; 6. get user's details. 7. post a tweet with gif 8. post a tweet with video

Prerequisites

You must have a developer account with Twitter to interact with the plugin. Create your development account at: https://developer.twitter.com/en/dashboard

How to setup

I. How to get Keys

The keys that you need are in your Twitter developer account -> Your app -> Keys and Tokens

Plugin field ConsumerPublic and ConsumerSecret are Consumer API keys from the dev account.

Same for Access tokens, access level should be Read & Write.

II. Setting up Keys in Plugin Settings

When you've got your keys from Developer Account, place them in plugin settings fields as shown:

III. Get OAuth tokens

  1. Request new token and authorize user

At the first step, the user should give access to his account, for that on a button click (or other user interaction you want) set the first action to Twitter: Get tokens This action is used in 2 steps, at first step set field Auth current step to step_1

For step_1 also set a callback URL encoded at field Step 1: Callback URL

Leave empty other fields, will be used later in another workflow.

Right after that set the next plugin action, Authorize user.

For the Oauth token field, set the Result of step 1 (Get tokens) Step 1 Oauth token:

2. Generate and save user’s tokens

These actions will redirect the user to the Twitter authorization page. When the user is redirected back to your application, there are 2 events that should be configured.

  1. The Event when the user denied access to your application, it is called Twitteraccount A User denied access, and you can do whatever you want to warn the user about it.

2. The user gave access and tokens from the callback are ready to use here on the first action set Twitter:Get tokens (same action from step_1).

But set fields for step_2

Next, save the obtained tokens to the current user. For example:

To refresh tokens, set the same actions from step 1:

Plugin Events

  • A Twitter account Callback Tokens ready: Event used when account callback token is available

  • A Twitter account User denied access: Event used when user account is denied access

Plugin Actions

  • Twitter: Post New Tweet

  • Twitter: Delete Tweet

  • Twitter: Retweet Or Cancel Retweet

  • Twitter: Like Tweet

  • Twitter: Load Timeline

  • Twitter: Get User Details

  • Twitter: Get Tokens

  • Twitter: Search Tweets

  • Twitter: Upload Picture

  • Twitter: Post With Picture

  • Twitter: Upload GIF

  • Twitter: Post With GIF

  • Twitter: Upload Video

  • Twitter: Post With Video

  • Authorize User With A Twitter Account

Update 24.07.20 - New Actions

  • Twitter: Upload picture

  • Twitter: Post with a picture

Update 18.08.20 - New Actions

  • Twitter: Upload GIF

  • Twitter: Post with GIF

Update 13.11.20 - New Actions

  • Twitter: Upload Video

  • Twitter: Post with Video

Plugin Element Proprieties

This plugin has visual element Twitter account which should be used on page .

Element Properties: No properties

Element Events

  • Callback Tokens ready: this event is triggered once the tokens from the Twitter: Get tokens action Step 1 are ready and can be used. Use this event to trigger Step 2 of Twitter: Get tokens action.

  • User denied access: this event is triggered if the user is denied access to Twitter.

Element Actions

Authorize user: the action to be called once Step 1 of the Twitter: Get tokens plugin action has finished executing Properties OAuth token: pass here the result of Twitter: Get tokens action Step 1 - OAuth token.

Element Exposed States

  • Callback OAuth token: Callback OAuth token to be used in Step 2 of Twitter: Get tokens action.

  • Callback OAuth verifier: Callback OAuth verifier to be used in Step 2 of Twitter: Get tokens action.

PLUGIN ACTIONS

Twitter: Get Tokens

Is used to get tokens for Twitter authorization.

Action properties Auth current step: current authorization step. Available values: step_1 step_2

Step 1: Callback URL: The value that will be used as the URL a user is redirected to should they approve your application’s access to their account. Is used only if the previous property is set to ‘step_1’. Step 2: Callback OAuth token: OAuth token here must be the same as the oauth_token returned in step_1. You can get it from the TwitterAccount element’s ‘Callback OAuth token’ state. Is used only if the previous property is set to ‘step_2’.

Step 2: Callback OAuth verifier: OAuth verifier returned in the callback URL. You can get it from the TwitterAccount element’s ‘Callback OAuth verifier’ state. Is used only if the previous property is set to ‘step_2’.

Returned Values

error: URL of the page to open Step 1: Oauth token: OAuth token obtained on this step. Step 1: Oauth token secret: OAuth token secret obtained on this step. Step 1: Oauth callback confirmed: ‘yes’ if the OAuth callback was confirmed, or ‘no’ if it was not confirmed. Step 2: Oauth token: OAuth token obtained on step 2. Step 2: Oauth token secret: oauth token secret obtained on step 2. Step 2: User ID: ID of the user. Step 2: Username: username (screen name) of the user.

Twitter: Post New Tweet

Is used to post a tweet.

Action properties

Oauth from Step 2: OAuth value obtained on step 2 of the ‘Twitter: Get tokens’ action. Oauth secret from Step 2: OAuth secret obtained on step 2 of the ‘Twitter: Get tokens’ action. Text: text of the new tweet.

Returned values

Tweet ID: ID of the newly created tweet.

Twitter: Delete Tweet

Is used to delete a tweet.

Action properties

Oauth from Step 2: OAuth value obtained on step 2 of the ‘Twitter: Get tokens’ action. Oauth secret from Step 2: OAuth secret obtained on step 2 of the ‘Twitter: Get tokens’ action. Tweet ID: ID of the tweet to be deleted.

Returned values

Success: ‘yes’ in case of success, ‘no’ in case of error. Error: error message in case of an error.

Twitter: Get User Details

Is used to test if supplied user credentials are valid. Returns a 200 OK response code and a representation of the requesting user if authentication was successful; returns a 401 status code and an error message if not.

Action properties

Oauth from Step 2: OAuth value obtained on step 2 of the ‘Twitter: Get tokens’ action. Oauth secret from Step 2: OAuth secret obtained on step 2 of the ‘Twitter: Get tokens’ action. Request user email: When set to true, the email will be returned in the response as a string. If the user does not have an email address on their account, or if the email address is not verified, null will be returned.

Returned values

User ID: ID of the requesting user Name: name of the requesting user Screen Name: screen name of the requesting user Description: description for the requesting user Url: URL Followers count: followers count for the requesting user Friends count: friends count for the requesting user Listed count: listed count for the requesting user Created date: the date when the requesting user was created Favorites count: favorites count for the requesting user Is verified: ‘true’ if the requesting user is verified, otherwise ‘false’ Statuses count: statuses count for the requesting user Last status text: last status text of the requesting user Last status date: the date of the last status for the requesting user Last status id: ID of the last status for the requesting user Profile image url: profile image URL for the requesting user Profile banner url: profile banner URL for the requesting user User email: requesting user email Error: error message in case of an error

Twitter: Retweet or Cancel Retweet

Is used to retweet a tweet or untweet a retweeted status.

Action properties

Oauth from Step 2: OAuth value obtained on step 2 of the ‘Twitter: Get tokens’ action. Oauth secret from Step 2: OAuth secret obtained on step 2 of the ‘Twitter: Get tokens’ action. Tweet ID: ID of the tweet to be retweeted or untweeted. Action: action to be performed on the specified tweet.

Available values: Retweet Cancel retweet

Returned values

Success: ‘yes’ in case of success, ‘no’ in case of error Error: error message in case of an error

Twitter: Like Tweet

Is used to add a like to a tweet or remove the like from a tweet.

Action properties

Oauth from Step 2: OAuth value obtained on step 2 of the ‘Twitter: Get tokens’ action. Oauth secret from Step 2: OAuth secret obtained on step 2 of the ‘Twitter: Get tokens’ action. Tweet ID: ID of the tweet to add a like to or remove it. Action: action to be performed on the specified tweet.

Available values: Like Remove like

Returned values

Success: ‘yes’ in case of success, ‘no’ in case of error Error: error message in case of an error

Twitter: Search Tweets

Is used to return public statuses that match specified keywords.

Action properties

Oauth from Step 2: OAuth value obtained on step 2 of the ‘Twitter: Get tokens’ action. Oauth secret from Step 2: OAuth secret obtained on step 2 of the ‘Twitter: Get tokens’ action. Keywords: A comma-separated list of phrases or words. Punctuation and special characters will be considered part of the term they are adjacent to.

Returned values

Results: results for the given request in case of a successful response. Error: error message in case of an error.

Twitter: Load Timeline

Returns a collection of the most recent tweets (and Retweets for home timeline) posted by the authenticating user and the users they follow. The home timeline is central to how most users interact with the Twitter service. The user timeline is the equivalent of the one seen as a user's profile on Twitter.

Action properties

Oauth from Step 2: OAuth value obtained on step 2 of the ‘Twitter: Get tokens’ action. Oauth secret from Step 2: OAuth secret obtained on step 2 of the ‘Twitter: Get tokens’ action. Timeline: specifies whether to load current user tweets or his home timeline.

Available values: user home

Returned values

Tweet text list: a list of tweet texts Tweet object list: a list of tweet objects Tweet posted by list: a list of tweet authors names Error: error message in case of an error

Twitter: Upload Picture

Is used to upload a picture to Twitter.

Action properties

Oauth from Step 2: OAuth value obtained on step 2 of the ‘Twitter: Get tokens’ action. Oauth secret from Step 2: OAuth secret obtained on step 2 of the ‘Twitter: Get tokens’ action. Image: link to the image file (in most cases, Bubble File Uploader’s value).

Returned values

media_id: ID of the uploaded image. error: error message in case of an error.

Twitter: Post With Picture

Is used to post a tweet with a picture previously uploaded to Twitter.

Action properties

OAuth from Step 2: OAuth value obtained on step 2 of the ‘Twitter: Get tokens’ action. Oauth secret from Step 2: OAuth secret obtained on step 2 of the ‘Twitter: Get tokens’ action. Image id: media id of the image uploaded to Twitter, obtained as the result of the ‘Twitter: Upload picture’ action. Tweet text: text to the new tweet.

Returned values

tweet_id: ID of the newly created tweet. error: error message in case of an error.

Twitter: Upload GIF

Is used to upload a GIF to Twitter.

Action properties

Oauth from Step 2: OAuth value obtained on step 2 of the ‘Twitter: Get tokens’ action. Oauth secret from Step 2: OAuth secret obtained on step 2 of the ‘Twitter: Get tokens’ action. GIF file: link to the GIF file (in most cases, Bubble File Uploader’s value).

Returned values

media_id: ID of the uploaded GIF. error: error message in case of an error. status: status of the upload.

Twitter: Post With GIF

Is used to post a tweet with a GIF previously uploaded to Twitter.

Action properties

Oauth from Step 2: OAuth value obtained on step 2 of the ‘Twitter: Get tokens’ action. Oauth secret from Step 2: OAuth secret obtained on step 2 of the ‘Twitter: Get tokens’ action. Gif id: media id of the GIF file uploaded to Twitter, obtained as the result of the ‘Twitter: Upload GIF’ action. Tweet text: text to the new tweet.

Returned values

tweet_id: ID of the newly created tweet. error: error message in case of an error.

Twitter: Upload Video

Is used to upload a video to Twitter.

Action properties

Oauth from Step 2: OAuth value obtained on step 2 of the ‘Twitter: Get tokens’ action. Oauth secret from Step 2: OAuth secret obtained on step 2 of the ‘Twitter: Get tokens’ action. Video file: link to the video file (in most cases, Bubble File Uploader’s value).

Returned values

media_id: ID of the uploaded image. error: error message in case of an error. status: status of the upload.

Twitter: Post With Video

Is used to post a tweet with a video previously uploaded to Twitter.

Action properties

Oauth from Step 2: OAuth value obtained on step 2 of the ‘Twitter: Get tokens’ action. Oauth secret from Step 2: OAuth secret obtained on step 2 of the ‘Twitter: Get tokens’ action. Media id for the video: media id of the video uploaded to Twitter, obtained as the result of the ‘Twitter: Upload video’ action. Tweet text: text to the new tweet.

Returned values

tweet_id: ID of the newly created tweet. error: error message in case of an error.

Plugin States

Workflow example

Action Example - Post new tweet

To post a new tweet use action, Twitter: Post new tweet.

For this and other actions you need OAuth tokens from Step_2, you should have them saved by now, in the current user database.

This action returns the posted tweet ID, you can get it using the Result of step 1: Tweet ID

The same tokens are used for other actions.

Action Example - Post a new tweet with a picture

To post a new tweet with a picture you require two actions: Twitter: Upload picture and Twitter: Post with picture.

For both of these actions you need OAuth tokens from Step_2, you should have them saved by now in the current user database.

For the first action you’ll also need an image (up to 5 Mb) uploaded to the app using File Uploader:

For the second action you’ll need to use media_id from the previous action as the ‘Image id’, and the tweet text:

This action returns posted tweet ID, you can get it using Result of step 2 (Twitter: Post with picture): tweet_id

Action Example - Post new tweet with GIF

To post a new tweet with GIF, just like for posting a tweet with a picture you have to use two actions: Twitter: Upload GIF and Twitter: Post with GIF.

Set them up just the way as the actions for tweeting with a picture in the above example.

For the first action you’ll also need an animated gif uploaded to the app using File Uploader:

For the second action you’ll need to use Gif_id from the previous action as the ‘Gif id’, and the tweet text:

This action returns the posted tweet ID, you can get it from Result of step 2 (Twitter: Post with GIF): tweet_id.

Animated GIF recommendations

The GIF file size must not exceed 15 Mb.

A GIF may fail during Tweet creation even if it is within the file size limit. Adhere to the following constraints to improve success rates.

  • Resolution should be <= 1280x1080 (width x height)

  • Number of frames <= 350

  • Number of pixels (width * height * num_frames) <= 300 million

  • File size <= 15Mb

Action Example - Post new tweet with a video

To post a new tweet with video, like for posting a tweet with a picture or GIF, you have to use two actions: Twitter: Upload video and Twitter: Post with video.

Set them up just the way the actions for tweeting with picture or GIF in the above examples are set.

For the first action you’ll need a video file (up to 15 Mb, up to 140 seconds) uploaded to the app using File Uploader:

For the second action you’ll need to use media_id from the previous action as the ‘Media id for the video’, and the tweet text:

This action returns the posted tweet ID. You can get it from the Result of step 2 (Twitter: Post with video): tweet_id

Video specifications and recommendations

The video file size must not exceed 15 Mb. The video duration must be between 0.5 seconds and 140 seconds.

It may fail during upload to Twitter even if it is within the file size and the duration limit. Adhere to the following constraints to improve success rates.

  • Recommended Video Codec: H264 High Profile

  • Recommended Frame Rates: 30 FPS, 60 FPS

  • Recommended Video Resolution: 1280x720 (landscape), 720x1280 (portrait), 720x720 (square)

  • Recommended Minimum Video Bitrate: 5,000 kbps

  • Recommended Minimum Audio Bitrate: 128 kbps

  • Recommended Audio Codec: AAC LC

  • Recommended Aspect Ratio: 16:9 (landscape or portrait), 1:1 (square)

Changelogs

Update: 13.11.20 -

  • Added possibility to post tweet with video. Improved tweet with GIF support gifs up to 15Mb.

Update: 13.06.21

  • Added new actions for add threads

Demo to preview the settings: