A Dart wrapper for the Twitter API v1.1
This dart package provides a well documented wrapper for the Twitter v1.1 API.
To access the v2 endpoints, check out twitter-api-v2.
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
Twitter API key
Get your Twitter API key here.
Features
Implemented endpoints
The implemented API endpoints are available as methods in the corresponding service. 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.
Error handling
Requests made by the client can throw the following errors:
-
TimeoutException
when a request hasn't returned a response for some time (defaults to 10s, can be changed in theTwitterClient
). -
Response
when the received response does not have a 2xx status code. Most responses include additional error information that can be parsed manually from the response's body. Check out the Twitter Developer documentation of the endpoint for possible error responses (Hyperlinked in the dart doc for each endpoint). -
Other unexpected errors in unlikely events (for example when parsing the response).
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. Feel free to reach out to me to ask any questions.
Please make sure dartanalyzer
doesn't report any problems before opening a pull request.
Miscellaneous
- To generate json_serializable models
dart run build_runner build --delete-conflicting-outputs
Libraries
- api/abstract_twitter_client
- api/common/data/edit_control
- api/common/data/entities
- api/common/data/hashtag
- api/common/data/option
- api/common/data/poll
- api/common/data/symbol
- api/common/data/url
- api/common/data/user_mention
- api/direct_messages/direct_messages_service
- api/geo/data/bounding_box
- api/geo/data/coordinates
- api/geo/data/place
- api/lists/data/paginated_twitter_lists
- api/lists/data/twitter_list
- api/lists/lists_service
- api/media/data/additional_media_info
- api/media/data/media
- api/media/data/media_upload
- api/media/data/size
- api/media/data/sizes
- api/media/data/video_info
- api/media/media_service
- api/trends/data/trend
- api/trends/data/trend_location
- api/trends/data/trends
- api/trends/trends_service
- api/tweets/data/current_user_retweet
- api/tweets/data/quoted_status_permalink
- api/tweets/data/tweet
- api/tweets/data/tweet_search
- api/tweets/timeline_service
- api/tweets/tweet_search_service
- api/tweets/tweet_service
- api/twitter_client
- api/users/data/derived
- api/users/data/friendship
- api/users/data/location
- api/users/data/paginated_ids
- api/users/data/paginated_users
- api/users/data/relationship
- api/users/data/relationship_entity
- api/users/data/user
- api/users/data/user_entities
- api/users/user_service
- twitter_api
- The TwitterApi provides interfaces for requests to the Twitter API and parses the returned data models.