4

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.

3 Answers 3

3

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

3

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

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.