简体   繁体   中英

twitteR R API getUser with a username of only numbers

I am working in R with the twitteR package, which is meant to get information from Twitter through their API. After getting authentificated, I can download information about any user with the getUser function. However, I am not able to do so with usernames which are only numbers (for example, 1234). With the line getUser("1234") I get the following error message:

Error in twInterfaceObj$doAPICall(paste("users", "show", sep = "/"), params = params, : Not Found (HTTP 404).

Is there any way to get user information when the username is made completely of numbers? The function tries to search by ID instead of screenname when it finds only numbers.

Thanks in advance!

First of all, twitteR is deprecated in favour of rtweet, so you might want to look into that.

The specific user ID you've provided is a protected account, so unless your account follows it / has access to it, you will not be able to query it anyway.

Using rtweet and some random attempts to find a valid numerical user ID, I succeeded with this:

library(rtweet)
users <- c("989", "andypiper")
usr_df <- lookup_users(users)
usr_df

rtweet also has some useful coercion functions to force the use of screenname or ID ( as_screenname and as_userid respectively)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM