friendshipsCreate method

Future<User> friendshipsCreate({
  1. String? userId,
  2. String? screenName,
  3. bool? follow,
  4. String tweetMode = 'extended',
  5. TransformResponse<User> transform = defaultUserTransform,
})

Allows the authenticating user to follow (friend) the user specified in the ID parameter.

Returns the followed user when successful. Returns a string describing the failure condition when unsuccessful. If the user is already friends with the user a HTTP 403 may be returned, though for performance reasons this method may also return a HTTP 200 OK message even if the follow relationship already exists.

Actions taken in this method are asynchronous. Changes will be eventually consistent.

userId: The ID of the user to follow.

screenName: The screen name of the user to follow.

follow: Enable notifications for the target user.

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/accounts-and-users/follow-search-get-users/api-reference/post-friendships-create.

Implementation

Future<User> friendshipsCreate({
  String? userId,
  String? screenName,
  bool? follow,
  String tweetMode = 'extended',
  TransformResponse<User> transform = defaultUserTransform,
}) async {
  final body = <String, String>{}
    ..addParameter('user_id', userId)
    ..addParameter('screen_name', screenName)
    ..addParameter('follow', follow)
    ..addParameter('tweet_mode', tweetMode);

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