ballerinax/twitter Ballerina library



Connects to Twitter via Ballerina.

The Twitter API can be used to programmatically retrieve data and engage with the conversation on Twitter. When accessing Twitter through Ballerina Twitter Connector, It is required to register a developer application. By default, applications can only access public information on Twitter. Certain operations, such as those responsible for sending or receiving direct Messages and posting a tweet, require additional permissions from user before access user information. These permissions are not granted by default; you choose on a per-application basis whether to provide this access, and can control all the applications authorized on your account.

This module supports Twitter API v1.


Before using this connector in your Ballerina application, complete the following:


To use the Twitter connector in your Ballerina application, update the .bal file as follows:

Step 1: Import connector

Import the ballerinax/twitter module into the Ballerina project.

import ballerinax/twitter;

Step 2: Create a new connector instance

twitter:ConnectionConfig twitterConfig = {
    apiKey: "<apiKey>",
    apiSecret: "<apiSecret>",
    accessToken: "<accessToken>",
    accessTokenSecret: "<accessTokenSecret>"

twitter:Client twitterClient = check new(twitterConfig);

Step 3: Invoke connector operation

  1. You can post a tweet as follows with tweet method by passing content as a parameter.

    public function main() returns error? {
        string tweetContent = "Sample tweet";
        twitter:Tweet result = check twitterClient->tweet(tweetContent);
        io:println("Tweet: " + result.toString());
  2. Use bal run command to compile and run the Ballerina program.

You can find more samples here


import ballerinax/twitter;Copy


Released date: 11 months ago

Version: 3.3.0

License: Apache-2.0


Platform: java11

Ballerina version: 2201.7.0

GraalVM compatible: Yes

Pull count

Total: 81083

Current verison: 21184

Weekly downloads

Source repository


Marketing/Social Media Accounts



Other versions

See more...