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

Other versions

See more...