[英]Get username by id in Twitter Api
How can I get the user name by userid via a request to the Twitter Api?如何通过对 Twitter Api 的请求通过 userid 获取用户名?
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.其他一些方法,比如followers/ids
,给我们一个 ID 数组作为响应,我不确定如何从中获取他们的用户名。
The response of the method " followers/ids
" looks something like this:方法“ followers/ids
”的响应如下所示:
{
"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?如何从这些 ID 中获取用户名? I want something like what this webpage does.我想要类似这个网页的功能。
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.使用GET https://api.twitter.com/1.1/users/show.json?user_id=ID
并查看返回的 JSON 对象的screen_name
属性。
Reference: https://api.twitter.com/1.1/users/show.json参考: https : //api.twitter.com/1.1/users/show.json
Since you're getting multiple Twitter users from followers/ids
, you'll probably want to look up the corresponding screen names in bulk.由于您从followers/ids
获得多个 Twitter 用户,您可能希望批量查找相应的屏幕名称。 The users/show
API endpoint mentioned in the other answer only handles one user.另一个答案中提到的users/show
API 端点仅处理一个用户。 For up to 100 users, use users/lookup
.对于最多 100 个用户,请使用users/lookup
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.