Last active
July 1, 2022 04:39
-
-
Save cathandnya/cebd89ae8e3a7c6edf0456f8ff865619 to your computer and use it in GitHub Desktop.
users/lookup with dart_twitter_api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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