Skip to content
This repository has been archived by the owner on Nov 10, 2024. It is now read-only.

rtweet authentication not working for script running as a local job #438

Closed
wrahool opened this issue Aug 11, 2020 · 2 comments
Closed

rtweet authentication not working for script running as a local job #438

wrahool opened this issue Aug 11, 2020 · 2 comments

Comments

@wrahool
Copy link

wrahool commented Aug 11, 2020

Problem

I have an R script that fetches the friends of a user. It reads the API consumer keys and access keys and secrets from an RData file, creates a new token, and then uses this token to fetch the friends of a user. When I run this script normally (for example, by clicking "source" on RStudio) it runs just fine. However, when I do "Source as Local Job" it doesn't work, giving an authentication error.

Expected behavior

I expect the authentication to happen even when the script is running as a local job (in the background)

Reproduce the problem

library(rtweet)

load("../tokens/twitter_tokens/token1.Rdata")

tk <- create_token(
  app = token_name,
  consumer_key = api_key,
  consumer_secret = api_secret_key,
  access_token = access_token_key,
  access_secret = access_token_secret
)

users <- c("cnn", "bbc")

for(u in users) {
  u_data <- lookup_users(u)
  u_friends <- get_friends(
    u,
    n = u_data$friends_count,
    retryonratelimit = TRUE,
    token = tk
  )
  
  save(u_friends, file = paste0("../friends/", u, ".Rdata"))
  
}

rtweet version

## copy/paste output
packageVersion("rtweet")

[1] ‘0.7.0

Session info

## copy/paste output
sessionInfo()

R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] forcats_0.5.0   stringr_1.4.0   dplyr_1.0.1     purrr_0.3.4     readr_1.3.1     tidyr_1.1.1     tibble_3.0.3   
 [8] ggplot2_3.3.2   tidyverse_1.3.0 rtweet_0.7.0   

loaded via a namespace (and not attached):
 [1] tinytex_0.25     tidyselect_1.1.0 xfun_0.16        haven_2.3.1      colorspace_1.4-1 vctrs_0.3.2     
 [7] generics_0.0.2   blob_1.2.1       rlang_0.4.7      later_1.1.0.1    pillar_1.4.6     withr_2.2.0     
[13] glue_1.4.1       DBI_1.1.0        dbplyr_1.4.4     modelr_0.1.8     readxl_1.3.1     lifecycle_0.2.0 
[19] munsell_0.5.0    gtable_0.3.0     cellranger_1.1.0 rvest_0.3.6      httpuv_1.5.4     curl_4.3        
[25] fansi_0.4.1      broom_0.7.0      Rcpp_1.0.5       openssl_1.4.2    promises_1.1.1   backports_1.1.7 
[31] scales_1.1.1     jsonlite_1.7.0   fs_1.5.0         askpass_1.1      hms_0.5.3        stringi_1.4.6   
[37] grid_4.0.2       cli_2.0.2        tools_4.0.2      magrittr_1.5     crayon_1.3.4     pkgconfig_2.0.3 
[43] ellipsis_0.3.1   xml2_1.3.2       reprex_0.3.0     lubridate_1.7.9  assertthat_0.2.1 httr_1.4.2      
[49] rstudioapi_0.11  R6_2.4.1         compiler_4.0.2  

Token

## copy/paste output
rtweet::get_token()

<Token>
<oauth_endpoint>
 request:   https://api.twitter.com/oauth/request_token
 authorize: https://api.twitter.com/oauth/authenticate
 access:    https://api.twitter.com/oauth/access_token
<oauth_app> rsta******************
  key:    6j7I**********************************
  secret: <hidden>
<credentials> oauth_token, oauth_token_secret, user_id, screen_name
@llrs llrs mentioned this issue Feb 15, 2021
@llrs
Copy link
Collaborator

llrs commented Feb 17, 2021

I think you overwrite the token when you load it and then create it. Also if it is on that path and you set the path on R.environ correctly it should be picked up by rtweet automatically. Perhaps on the local jobs it doesn't load the environment variables?

hadley added a commit that referenced this issue Mar 4, 2021
* Deprecate set_renv in favour of cache
* Default cache to FALSE
* Export token_cache_path()
* Import deprecated to match recommended style

Fixes #438
@hadley
Copy link
Collaborator

hadley commented Mar 9, 2021

@llrs I have verified that local jobs are child processes so that env vars are forwarded. Given the absence of a reprex, no response from the original filer, and the fact that we're overhauling auth anyway, I'd suggest we close this issue.

@llrs llrs closed this as completed Mar 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants