createFavorite method

Future<Tweet> createFavorite({
  1. required String id,
  2. bool? includeEntities,
  3. bool? includeExtEditControl,
  4. String tweetMode = 'extended',
  5. TransformResponse<Tweet> transform = defaultTweetTransform,
})

Favorites (likes) the Tweet specified in the ID parameter as the authenticating user. Returns the favorite Tweet when successful.

The process invoked by this method is asynchronous. The immediately returned Tweet object may not indicate the resultant favorited status of the Tweet. A 200 OK response from this method will indicate whether the intended action was successful or not.

id: The numerical ID of the Tweet to like.

includeEntities: The entities node will not be included when set to false.

includeExtEditControl: The includeExtEditControl node will not be included when set to false. See https://developer.twitter.com/en/docs/twitter-api/v1/edit-tweets

tweetMode: When set to extended, uses the extended Tweets. See https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/intro-to-tweet-json#extendedtweet.

transform: Can be used to parse the request. By default, the response is parsed in an isolate.

See https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-favorites-create.

Implementation

Future<Tweet> createFavorite({
  required String id,
  bool? includeEntities,
  bool? includeExtEditControl,
  String tweetMode = 'extended',
  TransformResponse<Tweet> transform = defaultTweetTransform,
}) async {
  final body = <String, String>{}
    ..addParameter('id', id)
    ..addParameter('include_entities', includeEntities)
    ..addParameter('include_ext_edit_control', includeExtEditControl)
    ..addParameter('tweet_mode', tweetMode);

  return client
      .post(
        Uri.https('api.twitter.com', '1.1/favorites/create.json'),
        body: body,
      )
      .then(transform);
}