getUserDataV2 static method
get user info.
use Twitter API v2.
https://api.twitter.com/2/users
Implementation
static Future<User> getUserDataV2(
String apiKey,
String apiSecretKey,
String accessToken,
String accessTokenSecret,
String userId,
) async {
try {
final token = await Oauth2.getBearerToken(apiKey: apiKey, apiSecretKey: apiSecretKey);
if (token?.isEmpty ?? true) {
throw Exception();
}
final params = await httpGetFromBearerToken(
'$USER_LOCKUP_URI/$userId',
query: {'user.fields': 'id,name,username,profile_image_url'},
bearerToken: token!,
);
// migrate v2 user model to v1.0a user model.
final data = params['data'] as Map<String, dynamic>;
data['id'] = int.parse(data['id'] as String);
final userDict = {
...data,
'profile_image_url_https': data['profile_image_url'],
'screen_name': data['username'],
};
return User(userDict);
} on Exception {
rethrow;
}
}