Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
andrescaso
Resolver I
Resolver I

Connect to twitter api via R script

Hi

I have a problem with my R script,

library("ROAuth");
library("rtweet");
library(dplyr);

consumer_key <- "xxx"
consumer_secret <-"xxx"
access_token <-"319367740-xxx"
access_secret <-"xxx"

token <- create_token(
app = "xx",
consumer_key = consumer_key,
consumer_secret = consumer_secret,
access_token = access_token,
access_secret = access_secret)
chs_tweets <- get_timeline(user = "ClubHipico_Stgo", n = 100000, parse = TRUE, check = TRUE, include_rts = FALSE)
chs_flw <- get_followers("ClubHipico_Stgo", n = "all")
chs_flw_data <- lookup_users(chs_flw$user_id)
hch_tweets <- get_timeline(user = "hipodromo_chile", n = 100000, parse = TRUE, check = TRUE, include_rts = FALSE)
hch_flw <- get_followers("hipodromo_chile", n = "all")

hch_flw_data <- lookup_users(hch_flw$user_id)

 

The script work fine in R by the way

 

after a several proves, i think this is the problem:
if i use the get_followers function only once, the script works fine, for example, use the script only with the ClubHipico_Stgo user, the chs_flw table get all the users,
but if run the script and i put two times the get_followers function, power bi show me this error:
Error in if (x) { : argumento tiene longitud cero
Calls: lookup_users ... lookup_users_ -> .user_lookup -> .ids_type -> .id_type
Ejecución interrumpida

Because the 2 followers tables (chs_flw, hch_flw) get 0 followers

 

Please help me

 

Regards

1 ACCEPTED SOLUTION

Thanks yingyinr

 

I found a similar solution in this page, the trick is pass to the USER argument in a list and run the code with a for statement

https://github.com/ropensci/rtweet/issues/238

 

Regards

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @andrescaso ,

Please review the solution in the following thread, hope it can help you.

R - argument is of length zero in if statement

Best Regards

Rena

Thanks yingyinr

 

I found a similar solution in this page, the trick is pass to the USER argument in a list and run the code with a for statement

https://github.com/ropensci/rtweet/issues/238

 

Regards

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors