Related modules

ballerinax/twitter
Overview
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.
Prerequisites
Before using this connector in your Ballerina application, complete the following:
-
Create Twitter Developer Account
-
Obtain tokens
Follow this link to obtain the API key, API key secret, Access token and Access token secret.
Quickstart
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.
Step 2: Create a new connector instance
Step 3: Invoke connector operation
-
You can post a tweet as follows with
tweet
method by passing content as a parameter. -
Use
bal run
command to compile and run the Ballerina program.
Clients
twitter: Client
Ballerina Twitter connector provides the capability to access Twitter API. This connector lets you to perform operations related to Tweets and users.
Constructor
Initializes the connector. During initialization you have to pass API credentials. Create a Twitter Developer Account and obtain credentials following this guide.
init (ConnectionConfig config)
- config ConnectionConfig - Configuration for the connector
tweet
function tweet(string tweetText, string? url, UpdateTweetOptions? updateTweetOptions) returns Tweet|error
Update the user's Tweet.
Parameters
- tweetText string - Text of tweet to update
- url string? (default ()) - Link attachment url
- updateTweetOptions UpdateTweetOptions? (default ()) - Options for tweet update
replyTweet
Reply to a Tweet.
Parameters
- tweetText string - Text of tweet to update
- replyID int - Tweet id to be replyed
- url string? (default ()) - URL of attachment
retweet
Retweet a Tweet.
Parameters
- id int - Numerical ID of a status
deleteRetweet
Delete a Retweet.
Parameters
- id int - Numerical ID of a status
search
function search(string queryStr, SearchOptions? searchOptions) returns Tweet[]|error
Search for Tweets matching a query.
Parameters
- queryStr string - Query string need to be searched
- searchOptions SearchOptions? (default ()) - Optional parameter which specify the search options
showStatus
function showStatus(int id, boolean? trimUser, boolean? includeMyRetweet, boolean? includeEntities, boolean? includeExtAltText, boolean? includeCardUri) returns Tweet|error
Show a Tweet.
Parameters
- id int - Numerical ID of a status
- trimUser boolean? (default ()) - User object including only numerical ID. Omit parameter to receive the complete user object
- includeMyRetweet boolean? (default ()) - Include retweets
- includeEntities boolean? (default ()) - Include entities nodes
- includeExtAltText boolean? (default ()) - Include alt text of media entities
- includeCardUri boolean? (default ()) - Include card uri attributes
deleteTweet
Delete a Tweet.
Parameters
- id int - Numerical ID of a status
getUser
Get a User object.
Parameters
- userId int - Numerical ID of a specific user
getUserByHandle
Get a User object by username or handle.
Parameters
- handleName string - Username or handle of a specific user
getFollowers
Get a user's followers.
Parameters
- userId int - Numerical ID of a specific user
getFollowing
Get a user's following.
Parameters
- userId int - Numerical ID of a specific user
getUserTimeline
function getUserTimeline(int? count, int? sinceId, int? maxId, boolean? trimUser, boolean? excludeReplies, boolean? includeEntities) returns Tweet[]|error
Get a user's tweets in timeline.
Parameters
- count int? (default ()) - Number of tweets returned
- sinceId int? (default ()) - Minimum tweet ID
- maxId int? (default ()) - Maximum tweet ID
- trimUser boolean? (default ()) - User object including only numerical ID. Omit parameter to receive the complete user object
- excludeReplies boolean? (default ()) - Include retweets
- includeEntities boolean? (default ()) - Include entities nodes
getUserTweets
Get Tweets of a specific handle.
Parameters
- handleName string - Handle name of user
getLast10Tweets
function getLast10Tweets(int? sinceId, int? maxId, boolean? trimUser, boolean? excludeReplies, boolean? includeEntities) returns Tweet[]|error
Get a user's last ten tweets.
Parameters
- sinceId int? (default ()) - Minimum tweet ID
- maxId int? (default ()) - Maximum tweet ID
- trimUser boolean? (default ()) - User object including only numerical ID. Omit parameter to receive the complete user object
- excludeReplies boolean? (default ()) - Include retweets
- includeEntities boolean? (default ()) - Include entities nodes
Records
twitter: ConnectionConfig
Client configuration details.
Fields
- Fields Included from * ConnectionConfig
- auth AuthConfig
- httpVersion HttpVersion
- http1Settings ClientHttp1Settings
- http2Settings ClientHttp2Settings
- timeout decimal
- forwarded string
- poolConfig PoolConfiguration
- cache CacheConfig
- compression Compression
- circuitBreaker CircuitBreakerConfig
- retryConfig RetryConfig
- responseLimits ResponseLimitConfigs
- secureSocket ClientSecureSocket
- proxy ProxyConfig
- validation boolean
- anydata...
- auth never? -
- apiKey string - API Key for Twitter
- apiSecret string - API Secret for Twitter
- accessToken string - Access token for Twitter
- accessTokenSecret string - Access token secret for Twitter
twitter: Entity
Define Entity.
Fields
- hashtags json? - Hashtags mentioned in the tweet
- symbols json? - Symbols exists
- user_mentions json? - Users mentioned in the tweet
- urls json? - Urls retated to that tweet
twitter: GeoLocation
Define the geo location details.
Fields
- latitude float? - Latitude of the location
- longitude float? - Longitude of the location
twitter: Location
Define the location details.
Fields
- woeid int? - Where On Earth IDentifier
- countryName string? - Country name
- countryCode string? - Country code
- name string? - Name of the location
- placeType PlaceType? - Longitude of the location
- url string? - Location URL
twitter: PlaceType
Define the place type.
Fields
- name string? - Name of the place
- code int? - Location code of the place
twitter: SearchOptions
Define search request options.
Fields
- count int? - Number of tweets to return per page, up to a maximum of 100
- geocode string? - Geo location of tweets by users
- lang string? - Restricts tweets to a language
- locale string? - Specify the language of the query sent
- result_type string? - Type of search results returned
- until string? - Return tweets created before the given date
- since_id int? - Minimum tweet Id
- max_id int? - Maximum tweet Id
- include_entities boolean? - Include entities nodes
twitter: Tweet
Define a Tweet.
Fields
- created_at string - Created time of the status
- id int - Id of the status
- id_str string? -
- text string - Text message of the status
- truncated boolean? - Whether the status is truncated or not
- entities json? - Entity of status
- 'source json? -
- in_reply_to_status_id int? - ID of an existing status that update is in reply to
- in_reply_to_status_id_str string? - ID of an existing status that update is in reply to in string
- in_reply_to_user_id int? - ID of an existing user update is in reply to
- in_reply_to_user_id_str string? - ID of an existing user update is in reply to in string
- in_reply_to_screen_name string? - Screen name of an existing user update is in reply to in string
- user User - Detail of user post
- geo GeoLocation? - Geo location details (longitude and latitude)
- coordinates json? - Coordinates of location where posted
- place json? - Location name where posted
- contributors json? - Contributors to a tweet
- is_quote_status boolean? - Indicate the quote status
- retweet_count int? - Count of the retweeted status
- favorite_count int? - Count of the favourites
- favorited boolean? - Whether the status is favorited or not
- retweeted boolean? - Whether the status is retweeted or not
- possibly_sensitive boolean? - Sensitivie or not
- lang string? - Language of tweet
twitter: UpdateTweetOptions
Define update tweet options.
Fields
- media_ids string? - Specify the language of the query sent
- possibly_sensitive boolean? - Whether sensitve ot not
- lat string? - Latitude of tweet posted location
- long string? - Longitude of tweet posted location
- place_id string? - Place Id of tweet posted location
- display_coordinates boolean? - Cordinates related to tweet posted location
- trim_user boolean? - Reduce user details to show(only ID)
twitter: User
Define User.
Fields
- id int - Id of user
- id_str string - Id of user in string
- name string - Display name of user
- screen_name string - Screen name of user
- location string? - Location of user
- description string? - Description about the user
- url string? - Urls associated with user
- followers_count int? - Count of the followers
- friends_count int? - Count of the friends(User's following)