I am keen to get a list of usernames and fullnames names from a specific twitter list using R. I could not see a function in any package but this code works
The solution from Molx does not seem to work any more. The problem seems to lie in
api.url <- paste0("https://api.twitter.com/1.1/lists/members.json?slug=",
twlist, "&owner_screen_name=", twowner, "&count=5000")
This URL does not seem valid, for any twlist or twowner that I tried. EDIT : the problem comes from the authentication I think as I get
{"errors":[{"code":215,"message":"Bad Authentication data."}]}
I think I'm authenticated with this
## Twitter authentication,
consumer_key = "xxxxx"
consumer_secret = "xxx"
access_token = "xxxxx"
access_secret = "xxx"
setup_twitter_oauth(consumer_key, consumer_secret, access_token,
access_secret)
Where does the problem come from ?
EDIT : When I enter get_oauth_sig() I get the result below
> twitteR:::get_oauth_sig()
NULL
twitter
key: XXXXXXX
secret:
oauth_token, oauth_token_secret
---
Is this normal ?
The solution from Molx does not seem to work any more. The problem seems to lie in
api.url <- paste0("https://api.twitter.com/1.1/lists/members.json?slug=",
twlist, "&owner_screen_name=", twowner, "&count=5000")
This URL does not seem valid, for any twlist or twowner that I tried. EDIT : the problem comes from the authentication I think as I get
{"errors":[{"code":215,"message":"Bad Authentication data."}]}
I think I'm authenticated with this
## Twitter authentication,
consumer_key = "xxxxx"
consumer_secret = "xxx"
access_token = "xxxxx"
access_secret = "xxx"
setup_twitter_oauth(consumer_key, consumer_secret, access_token,
access_secret)
Where does the problem come from ?
EDIT : When I enter get_oauth_sig() I get the result below
> twitteR:::get_oauth_sig()
NULL
twitter
key: XXXXXXX
secret:
oauth_token, oauth_token_secret
---
Is this normal ?
EDIT : I solve the problem by replacing POST by GET
library(rjson)
library(twitteR)
consumer_key = "xxxxx"
consumer_secret = "xxx"
access_token = "xxxxx"
access_secret = "xxx"
setup_twitter_oauth(consumer_key, consumer_secret, access_token,
access_secret)
https://twitter.com/ivalerio/lists/justice?lang=fr
twlist <- "d-put-s-2017-2022"
twowner <- "ivalerio"
api.url <- paste0("https://api.twitter.com/1.1/lists/members.json?slug=",
twlist, "&owner_screen_name=", twowner, "&count=5000")
response <- GET(api.url, config(token=twitteR:::get_oauth_sig()))
#Count = 5000 is the number of names per result page,
# which for this case simplifies things to one page.
# This returns a JSON response which we can read using fromJSON:
response.list <- fromJSON(content(response, as = "text", encoding = "UTF-8"))
# Now, we have a list where each element is the Twitter data of one Twitter-list member. To extract their names and user_names:
users.names <- sapply(response.list$users, function(i) i$name)
users.screennames <- sapply(response.list$users, function(i) i$screen_name)
# Which are:
head(users.names)