Reputation: 192
How can I get the user name by userid via a request to the Twitter Api?
Some other methods, like followers/ids
, give us as response an array of IDs, from which I am not sure how I can get their usernames.
The response of the method "followers/ids
" looks something like this:
{
"ids": [782235942383972400, 16664925, 839240398010781700, 39606379, 19713521,
...
...
...
...
...
899462802, 198446818],
"next_cursor": 0,
"next_cursor_str": "0",
"previous_cursor": 0,
"previous_cursor_str": "0"
}
How I can get the username from these ids? I want something like what this webpage does.
Upvotes: 4
Views: 14078
Reputation: 6772
This has changed in the Twitter 2 api. To get the username of a single user:
https://api.twitter.com/2/users/123456
For multiple users (up to 100), use:
https://api.twitter.com/2/users?ids=123456,456789"
Click here for more info
Upvotes: 4
Reputation: 151855
Since you're getting multiple Twitter users from followers/ids
, you'll probably want to look up the corresponding screen names in bulk. The users/show
API endpoint mentioned in the other answer only handles one user. For up to 100 users, use users/lookup
.
Upvotes: 1
Reputation: 2273
Use GET https://api.twitter.com/1.1/users/show.json?user_id=ID
and see the screen_name
property of the returned JSON object.
Reference: https://api.twitter.com/1.1/users/show.json
Upvotes: 3