Skip to content

Instantly share code, notes, and snippets.

@cathandnya
Last active July 1, 2022 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cathandnya/cebd89ae8e3a7c6edf0456f8ff865619 to your computer and use it in GitHub Desktop.
Save cathandnya/cebd89ae8e3a7c6edf0456f8ff865619 to your computer and use it in GitHub Desktop.
users/lookup with dart_twitter_api
Future<List<User>> twitterLookup({
required TwitterApi twitter,
List<String>? screenNames,
List<String>? userIds,
}) async {
var params = <String, String>{};
if (screenNames != null) {
params['screen_name'] = screenNames.join(",");
}
if (userIds != null) {
params['user_id'] = userIds.join(",");
}
try {
final response = await twitter.client.get(
Uri.https('api.twitter.com', '1.1/users/lookup.json', params),
);
final List<dynamic> results = json.decode(response.body);
return results.map((e) => User.fromJson(e)).toList();
} catch (e) {
if (e is Response) {
throw Exception(e.body);
} else {
rethrow;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment