Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Latest commit 345c98c Apr 16, 2019

README.md

Build Status

Ballerina Twitter Connector

The Twitter connector allows you to tweet, retweet, untweet, and search for tweets through the Twitter REST API. It handles OAuth 2.0 authentication. You can also retrieve and destroy a status, retrieve closest trend locations, and top trends using the connector.

Compatibility

Ballerina Language Version Twitter API version
0.991.0 1.1

The following sections provide you with information on how to use the Ballerina Twitter connector.

Contribute To develop

Clone the repository by running the following command

git clone https://github.com/wso2-ballerina/module-twitter.git

Working with Twitter Connector actions

All the actions return valid response or error. If the action is a success, then the requested resource will be returned. Else error will be returned.

In order for you to use the Twitter Connector, first you need to create a Twitter Client endpoint.

twitter:TwitterConfiguration twitterConfig = {
    clientId: "<clientId>",
    clientSecret: "<clientSecret>",
    accessToken: "<accessToken>",
    accessTokenSecret: "<accessTokenSecret>"
};

twitter:Client twitterClient = new(twitterConfig);
Example
import ballerina/io;
import wso2/twitter;

twitter:TwitterConfiguration twitterConfig = {
    clientId: "<clientId>",
    clientSecret: "<clientSecret>",
    accessToken: "<accessToken>",
    accessTokenSecret: "<accessTokenSecret>"
};

twitter:Client twitterClient = new(twitterConfig);

public function main(string... args) {
    string status = "Twitter endpoint test";
    var result = twitterClient->tweet(status);
    if (result is twitter:Status) {
        // If successful, print the tweet ID and text.
        io:println("Tweet ID: ", result.id);
        io:println("Tweet: ", result.text);
    } else {
        // If unsuccessful, print the error returned.
        io:println("Error: ", result);
    }
}
You can’t perform that action at this time.