A Dart wrapper for the Twitter API

pub test

This dart package provides a well documented wrapper for the Twitter API.

Why use this package?

To make the usage as convenient and comfortable as possible, this package provides interfaces for the various endpoints of the Twitter API. Documentation for each request is available as dart docs and each request's parameters can be changed as named parameters.

The various data structures returned by Twitter are parsed into data models in an isolate.

Example usage

final TwitterApi twitterApi = TwitterApi(
  client: TwitterClient(
    consumerKey: 'your_consumer_key',
    consumerSecret: 'your_consumer_secret',
    token: 'your_token',
    secret: 'your_secret',
  ),
);

// Get the last 200 tweets from your home timeline
final List<Tweet> homeTimeline = await twitterApi.timelineService
    .homeTimeline(
      count: 200,
      includeEntities: false,
    )
    .catchError(handleError);

// Print the text of each Tweet
homeTimeline.forEach((tweet) => print(tweet.fullText))

Twitter API key

Get your Twitter API key here.

Features

Implemented endpoints

An API endpoint is considered 'implemented' when a method for it exists in the package. Once implemented, the request parameters can be set through named parameters and the response will be parsed into a data object for maximum convenience.

Find a list of implemented endpoints here.


If an API endpoint is not yet implemented, a request can be made to that endpoint by manually using the TwitterClient from the TwitterApi object.

See Making a custom request to the Twitter API for an example.


For an example of uploading media files to Twitter, see Attaching media to a Tweet.

Development

Contribution

I appreciate any contributions to this package. Any not yet implemented endpoints can be added similarly to the other implementations. Please make sure dartanalyzer doesn't report any problems before opening a pull request.

Miscellaneous

  • To generate json_serializable models
    • pub run build_runner build --delete-conflicting-outputs

Libraries

abstract_twitter_client
bounding_box
coordinates
derived
direct_messages_service
entities
hashtag
location
media
media_service
media_upload
option
paginated_users
place
poll
size
sizes
symbol
timeline_service
tweet
tweet_search_service
tweet_service
twitter_api
The TwitterApi provides interfaces for requests to the Twitter API and parses the returned data models. [...]
twitter_client
url
user
user_mention
user_service