dart_twitter_api 0.2.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 78

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

0.2.1 #

  • Fix parsing a PaginatedUsers response

0.2.0 #

  • Add user service

0.1.1 #

  • Add support to change the twitter client default timeout
  • Allow to change the twitter client api keys & token after instantiation

0.1.0+1 #

  • Update readme

0.1.0 #

  • Initial release

example/main.dart

import 'package:dart_twitter_api/twitter_api.dart';

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

Future<void> main() async {
  try {
    // Get the last 200 tweets from your home timeline
    final homeTimeline = await twitterApi.timelineService.homeTimeline(
      count: 200,
    );

    // Print the text of each Tweet
    homeTimeline.forEach((tweet) => print(tweet.fullText));
  } catch (error) {
    // If no response is received or if the response status code does not start
    // with 2, an exception is thrown
    print('error while requesting home timeline: $error');
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  dart_twitter_api: ^0.2.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:dart_twitter_api/api/abstract_twitter_client.dart';
import 'package:dart_twitter_api/api/common/data/entities.dart';
import 'package:dart_twitter_api/api/common/data/entities.g.dart';
import 'package:dart_twitter_api/api/common/data/hashtag.dart';
import 'package:dart_twitter_api/api/common/data/hashtag.g.dart';
import 'package:dart_twitter_api/api/common/data/option.dart';
import 'package:dart_twitter_api/api/common/data/option.g.dart';
import 'package:dart_twitter_api/api/common/data/poll.dart';
import 'package:dart_twitter_api/api/common/data/poll.g.dart';
import 'package:dart_twitter_api/api/common/data/symbol.dart';
import 'package:dart_twitter_api/api/common/data/symbol.g.dart';
import 'package:dart_twitter_api/api/common/data/url.dart';
import 'package:dart_twitter_api/api/common/data/url.g.dart';
import 'package:dart_twitter_api/api/common/data/user_mention.dart';
import 'package:dart_twitter_api/api/common/data/user_mention.g.dart';
import 'package:dart_twitter_api/api/direct_messages/direct_messages_service.dart';
import 'package:dart_twitter_api/api/geo/data/bounding_box.dart';
import 'package:dart_twitter_api/api/geo/data/bounding_box.g.dart';
import 'package:dart_twitter_api/api/geo/data/coordinates.dart';
import 'package:dart_twitter_api/api/geo/data/coordinates.g.dart';
import 'package:dart_twitter_api/api/geo/data/place.dart';
import 'package:dart_twitter_api/api/geo/data/place.g.dart';
import 'package:dart_twitter_api/api/media/data/media.dart';
import 'package:dart_twitter_api/api/media/data/media.g.dart';
import 'package:dart_twitter_api/api/media/data/media_upload.dart';
import 'package:dart_twitter_api/api/media/data/media_upload.g.dart';
import 'package:dart_twitter_api/api/media/data/size.dart';
import 'package:dart_twitter_api/api/media/data/size.g.dart';
import 'package:dart_twitter_api/api/media/data/sizes.dart';
import 'package:dart_twitter_api/api/media/data/sizes.g.dart';
import 'package:dart_twitter_api/api/media/media_service.dart';
import 'package:dart_twitter_api/api/tweets/data/quoted_status_permalink.dart';
import 'package:dart_twitter_api/api/tweets/data/quoted_status_permalink.g.dart';
import 'package:dart_twitter_api/api/tweets/data/tweet.dart';
import 'package:dart_twitter_api/api/tweets/data/tweet.g.dart';
import 'package:dart_twitter_api/api/tweets/data/tweet_search.dart';
import 'package:dart_twitter_api/api/tweets/data/tweet_search.g.dart';
import 'package:dart_twitter_api/api/tweets/timeline_service.dart';
import 'package:dart_twitter_api/api/tweets/tweet_search_service.dart';
import 'package:dart_twitter_api/api/tweets/tweet_service.dart';
import 'package:dart_twitter_api/api/twitter_client.dart';
import 'package:dart_twitter_api/api/users/data/derived.dart';
import 'package:dart_twitter_api/api/users/data/derived.g.dart';
import 'package:dart_twitter_api/api/users/data/location.dart';
import 'package:dart_twitter_api/api/users/data/location.g.dart';
import 'package:dart_twitter_api/api/users/data/paginated_users.dart';
import 'package:dart_twitter_api/api/users/data/paginated_users.g.dart';
import 'package:dart_twitter_api/api/users/data/user.dart';
import 'package:dart_twitter_api/api/users/data/user.g.dart';
import 'package:dart_twitter_api/api/users/user_service.dart';
import 'package:dart_twitter_api/twitter_api.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
56
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
78
Learn more about scoring.

We analyzed this package on Jul 10, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14

Analysis suggestions

Package not compatible with runtime flutter-web on web

Because:

  • package:dart_twitter_api/api/abstract_twitter_client.dart that imports:
  • package:dart_twitter_api/twitter_api.dart that imports:
  • package:dart_twitter_api/src/utils/transforms.dart that imports:
  • package:dart_twitter_api/src/utils/isolates_io.dart that imports:
  • dart:isolate

Package not compatible with runtime js

Because:

  • package:dart_twitter_api/api/abstract_twitter_client.dart that imports:
  • package:dart_twitter_api/twitter_api.dart that imports:
  • package:dart_twitter_api/src/utils/transforms.dart that imports:
  • package:dart_twitter_api/src/utils/isolates_io.dart that imports:
  • dart:isolate

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
http ^0.12.1 0.12.1
intl ^0.16.1 0.16.1
json_annotation ^3.0.1 3.0.1
meta ^1.1.8 1.2.2 1.3.0-nullsafety
oauth1 ^1.0.4 1.0.4
Transitive dependencies
charcode 1.1.3
collection 1.14.13 1.15.0-nullsafety
convert 2.1.1
crypto 2.1.5
http_parser 3.1.4
path 1.7.0
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.2.0 1.3.0-nullsafety
Dev dependencies
build_runner ^1.7.3
json_serializable ^3.2.5
mockito ^4.1.1
pedantic ^1.8.0 1.9.2
test ^1.6.0