Wondering if there is an option to curate only my bookmarked tweets using the {rtweet} package. Thanks
You seem to have found the way to do this. But you found some problems with the following code you sent me by email:
devtools::install_github("ropensci/rtweet@devel")
library("rtweet")
client <- rtweet_client() # You'll need to provide the id and secret of your app.
client_as(client)
token_oa2 <- rtweet_oauth2()
ub <- user_bookmarks("BryanTegomoh",
expansion = NA, fields = NA, # To export everything: alt text, images, urls, ...
parse = FALSE, n = Inf, token = token_oa2)
saveRDS(ub, "my_bookmarks.RDS")
Problems with the authentication process are hard to detect for me.
Could you share the client output (simply what it returns when you print client) ?
It might also help to know which kind of API access you have (academic, paid, free, without elevated access,β¦) and when did you get it (recently or a year ago)?
It would also help if you provide the devel version you are using via packageVersion("rtweet")
and the exact commit via sessioninfo::session_info()
.
Even if the authentication worked to retrieve the bookmarked tweets you should use your user id instead of your user name. Your user id can be identified with user_self()
(which will require your oauth2 token to work).
Thanks Luis @llrs
Output of print client:
> client
$name
[1] "rtweet"
$id
[1] "6j7Ig4xzHlBr8uUJ5A4Ym0NTf"
$secret
[1] "k8njuFVfXaeZK86xDGDUgEqNvSXf5VGM1VwHHnAFeGS4HqhTfo"
$key
NULL
$token_url
[1] "https://api.twitter.com/2/oauth2/token"
$auth
[1] "oauth_client_req_auth_header"
$auth_params
list()
attr(,"class")
[1] "httr2_oauth_client"
attr(,"app")
[1] "rtweet"
attr(,"scopes")
[1] "tweet.read" "tweet.write" "tweet.moderate.write" "users.read" "follows.read" "follows.write"
[7] "offline.access" "space.read" "mute.read" "mute.write" "like.read" "like.write"
[13] "list.read" "list.write" "block.read" "block.write" "bookmark.read" "bookmark.write"
Free API access, obtained 2 years ago.
packageVersion("rtweet")
[1] β1.1.0.9009β
> sessioninfo::session_info()
β Session info βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
setting value
version R version 4.2.2 (2022-10-31 ucrt)
os Windows 10 x64 (build 22621)
system x86_64, mingw32
ui RStudio
language (EN)
collate English_United States.utf8
ctype English_United States.utf8
tz America/Chicago
date 2023-03-16
rstudio 2022.12.0+353 Elsbeth Geranium (desktop)
pandoc NA
β Packages βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
package * version date (UTC) lib source
cachem 1.0.6 2021-08-19 [1] CRAN (R 4.2.2)
callr 3.7.3 2022-11-02 [1] CRAN (R 4.2.2)
cli 3.4.1 2022-09-23 [1] CRAN (R 4.2.2)
colorspace 2.0-3 2022-02-21 [1] CRAN (R 4.2.2)
crayon 1.5.2 2022-09-29 [1] CRAN (R 4.2.2)
crul 1.3 2022-09-03 [1] CRAN (R 4.2.2)
curl 5.0.0 2023-01-12 [1] CRAN (R 4.2.2)
data.table 1.14.8 2023-02-17 [1] CRAN (R 4.2.2)
devtools 2.4.5 2022-10-11 [1] CRAN (R 4.2.2)
digest 0.6.30 2022-10-18 [1] CRAN (R 4.2.2)
dplyr 1.1.0 2023-01-29 [1] CRAN (R 4.2.2)
DT 0.27 2023-01-17 [1] CRAN (R 4.2.2)
ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.2.2)
fansi 1.0.4 2023-01-22 [1] CRAN (R 4.2.2)
fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.2.2)
fs 1.5.2 2021-12-08 [1] CRAN (R 4.2.2)
generics 0.1.3 2022-07-05 [1] CRAN (R 4.2.2)
ggplot2 3.4.1 2023-02-10 [1] CRAN (R 4.2.2)
ggrepel 0.9.3 2023-02-03 [1] CRAN (R 4.2.2)
glue 1.6.2 2022-02-24 [1] CRAN (R 4.2.2)
gtable 0.3.1 2022-09-01 [1] CRAN (R 4.2.2)
htmltools 0.5.4 2022-12-07 [1] CRAN (R 4.2.2)
htmlwidgets 1.6.1 2023-01-07 [1] CRAN (R 4.2.2)
httpcode 0.3.0 2020-04-10 [1] CRAN (R 4.2.2)
httpuv 1.6.9 2023-02-14 [1] CRAN (R 4.2.2)
httr 1.4.5 2023-02-24 [1] CRAN (R 4.2.2)
janitor 2.2.0 2023-02-02 [1] CRAN (R 4.2.2)
jsonlite 1.8.4 2022-12-06 [1] CRAN (R 4.2.2)
later 1.3.0 2021-08-18 [1] CRAN (R 4.2.2)
lazyeval 0.2.2 2019-03-15 [1] CRAN (R 4.2.2)
lifecycle 1.0.3 2022-10-07 [1] CRAN (R 4.2.2)
lubridate 1.9.2 2023-02-10 [1] CRAN (R 4.2.2)
magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.2.2)
memoise 2.0.1 2021-11-26 [1] CRAN (R 4.2.2)
mime 0.12 2021-09-28 [1] CRAN (R 4.2.0)
miniUI 0.1.1.1 2018-05-18 [1] CRAN (R 4.2.2)
munsell 0.5.0 2018-06-12 [1] CRAN (R 4.2.2)
pacman 0.5.1 2019-03-11 [1] CRAN (R 4.2.2)
pillar 1.8.1 2022-08-19 [1] CRAN (R 4.2.2)
pkgbuild 1.4.0 2022-11-27 [1] CRAN (R 4.2.2)
pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.2.2)
pkgload 1.3.2 2022-11-16 [1] CRAN (R 4.2.2)
plotly 4.10.1 2022-11-07 [1] CRAN (R 4.2.2)
plyr 1.8.8 2022-11-11 [1] CRAN (R 4.2.2)
prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.2.2)
processx 3.8.0 2022-10-26 [1] CRAN (R 4.2.2)
profvis 0.3.7 2020-11-02 [1] CRAN (R 4.2.2)
promises 1.2.0.1 2021-02-11 [1] CRAN (R 4.2.2)
ps 1.7.2 2022-10-26 [1] CRAN (R 4.2.2)
purrr 1.0.1 2023-01-10 [1] CRAN (R 4.2.2)
R6 2.5.1 2021-08-19 [1] CRAN (R 4.2.2)
Rcpp 1.0.10 2023-01-22 [1] CRAN (R 4.2.2)
rcrossref 1.2.0 2022-11-11 [1] CRAN (R 4.2.2)
remotes 2.4.2 2021-11-30 [1] CRAN (R 4.2.2)
rlang 1.1.0 2023-03-14 [1] CRAN (R 4.2.2)
rlist 0.4.6.2 2021-09-03 [1] CRAN (R 4.2.2)
rstudioapi 0.14 2022-08-22 [1] CRAN (R 4.2.2)
rtweet * 1.1.0.9009 2023-03-16 [1] Github (ropensci/rtweet@d6ee9e7)
scales 1.2.1 2022-08-20 [1] CRAN (R 4.2.2)
sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.2.2)
shiny 1.7.4 2022-12-15 [1] CRAN (R 4.2.2)
snakecase 0.11.0 2019-05-25 [1] CRAN (R 4.2.2)
stringi 1.7.8 2022-07-11 [1] CRAN (R 4.2.1)
stringr 1.5.0 2022-12-02 [1] CRAN (R 4.2.2)
tibble 3.1.8 2022-07-22 [1] CRAN (R 4.2.2)
tidyr 1.3.0 2023-01-24 [1] CRAN (R 4.2.2)
tidyselect 1.2.0 2022-10-10 [1] CRAN (R 4.2.2)
timechange 0.2.0 2023-01-11 [1] CRAN (R 4.2.2)
urlchecker 1.0.1 2021-11-30 [1] CRAN (R 4.2.2)
usethis 2.1.6 2022-05-25 [1] CRAN (R 4.2.2)
utf8 1.2.3 2023-01-31 [1] CRAN (R 4.2.2)
vctrs 0.5.2 2023-01-23 [1] CRAN (R 4.2.2)
viridisLite 0.4.1 2022-08-22 [1] CRAN (R 4.2.2)
xml2 1.3.3 2021-11-30 [1] CRAN (R 4.2.2)
xtable 1.8-4 2019-04-21 [1] CRAN (R 4.2.2)
[1] C:/Users/bryan/AppData/Local/R/win-library/4.2
[2] C:/Program Files/R/R-4.2.2/library
user_self()
Error in `default_cached_auth()`:
! No default authentication found. Pick existing auth with:
β’ auth_as('bryan_rtweet')
Run `rlang::last_trace()` to see where the error occurred.
βbryan_rtweetβ is the name I gave to the twitter dev app specifically for rtweet
Thanks for the info. It seems that you didnβt provide your credentials to the rtweet_client
and you were attempting to use rtweet default app. However, the default credentials are not activated to work with OAuth2.
When calling rtweet_client
you should provide the credentials you obtained in your developer dashboard. You can access them once you select your app under the Key and tokens (at the top of the page). Once you are there the last section of the page is βAuth 2.0 Client ID and Client Secretβ:
Youβll need to provide that information.
Note that the information provided would have allowed me to use your app! And thus affecting the rate limits or using it for purposes against the terms of services. The data I was expecting was:
<httr2_oauth_client>
name: rtweet
id: 6j7Ig4xzHlBr8uUJ5A4Ym0NTf
secret: <REDACTED>
token_url: https://api.twitter.com/2/oauth2/token
auth: oauth_client_req_auth_header
Which via the id I can match to the one you are trying to use.
Given this confusion I modified rtweet. If you install the latest devel version (1.1.0.9010) via install_github you will now be asked to provide your own ids and secrets. Thanks, for contributing to rtweet, I hope this is now clearer but let me know if this doesnβt fix this problem.
@llrs Thanks for taking the time to look into this. And thanks for updating the {rtweet} as a result of this.
The token_oa2 <- rtweet_oauth2()
takes me to this page suggesting authentication was unsuccessful
I donβt see the page you are redirected. Could you provide a screenshot of it?
Could you confirm that you provided your own Client ID and Client Secret by showing the new client you should have created and be using? Please provide the output of client_get()
and the output of the client you used/created.
Remember to only paste something like this:
<httr2_oauth_client>
name: rtweet
id: 6j7Ig4xzHlBr8uUJ5A4Ym0NTf
secret: <REDACTED>
token_url: https://api.twitter.com/2/oauth2/token
auth: oauth_client_req_auth_header
Hereβs the screenshot:
Without the client information I do not know why you see this error. Please provide the output of client_get()
or the client you used in your call to rtweet_oauth2()
.
client_get()
name: βrtweetβ
id: β6j7Ig4xzHlBr8uUJ5A4Ym0NTfβ
secret:
key: NULL
token_url: βhttps://api.twitter.com/2/oauth2/tokenβ
auth: βoauth_client_req_auth_headerβ
The current client you are using is the same as the old one, which I told you it doesnβt work.
It seems you havenβt created a client with your api key and api secret or at least you are not using it.
Once you create your own client (and the id it is not the same as 6j7Ig4xzHlBr8uUJ5A4Ym0NTf) the rtweet_oauth2
will work. Do you have your own developer account in Twitter? What do you see in https://developer.twitter.com/en/portal/dashboard?
Youβll need to click on the development app DoMoreWithR.
On the top there is a tab about tokens, click there.
Then at the bottom there should be a section about oauth2, where you can find the client ID and client secret to create your own client.
Sorry, instead of the app name you need to click the gear at the right of your DOMoreWithR app. In the next page youβll have to go to the βKey and tokensβ tab, and youβll find the section: βOAuth 2.0 Client ID and Client Secretβ at the bottom.
From there you can copy the client ID and client secret to create your own client. Good luck!
This is what the page looks like for me.
I can not find βOAuth 2.0 Client ID and Client Secretβ at the bottom
are you referring to API Key/Secret on this page?
Sorry it is hard to tell what is the whole process from an account that already have done it.
I have done it from an app that was at the same stage as yours.
It seems that until you donβt fill the User Authentication settings page you posted previously you cannot have OAuth 2 access.
Fill it like you showed in the image:
App permissions
Read and write and Direct message
I have never set up a request email from users as I donβt have a Terms of Service.
Type of App
Native App
Appinfo
Callback Uri: http://127.0.0.1:1410/
Website url: Whatever you prefer, your own twitter page or website.
The permisions of the APP are not that important but if you donβt provide the callback Uri correctly rtweet will not be able to use it.
But do not worry that you can change that later.
Once you fill the form and save youβll be shown a website with the information you need for rtweet_client()
:
Thank you @llrs for taking the time to look into this. Much appreciated. I hope this thread is helpful to others
Glad you finally got it to work!
This made me realize rtweet should provide its own client to ease its use.
I have added its own client for next release.