Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing bookmarked tweets #344

Closed
esanfar opened this issue Jul 20, 2019 · 29 comments
Closed

Importing bookmarked tweets #344

esanfar opened this issue Jul 20, 2019 · 29 comments

Comments

@esanfar
Copy link

esanfar commented Jul 20, 2019

I looked for a function to import own account bookmarks and I couldn't find anything. Bookmarking tweets was not universally available, but it is now, and it would be great to be able to import tweets saved in it.

@Arf9999
Copy link

Arf9999 commented Jul 20, 2019

There doesn't seem to be a Twitter API endpoint for bookmarks (yet?) https://developer.twitter.com/en/docs/api-reference-index

@llrs llrs mentioned this issue Feb 15, 2021
@llrs
Copy link
Member

llrs commented Feb 16, 2021

Still not available. Apparently it is something that twitter don't want to expose. Closing the issue, if they make it available open an issue again please

@llrs llrs closed this as completed Feb 16, 2021
@tchakravarty
Copy link

tchakravarty commented Jun 22, 2022

Hi @llrs

This seems to now be available: https://twittercommunity.com/t/build-with-bookmarks-on-the-twitter-api-v2/168804.

It would be great if rtweet exposed a get_bookmarks function based on this.

Thanks.

@llrs llrs added the API v2 label Jun 22, 2022
@llrs
Copy link
Member

llrs commented Jun 22, 2022

Thanks for the head up.
As it is with API v2 it will need to wait till release rtweet > 1.0.0 as next release is to prepare for API v2.

@llrs llrs reopened this Jun 22, 2022
@rbcavanaugh
Copy link

Any chance of some movement on this? Would love to be able to pull all of my bookmarks before twitter completely implodes. Thanks!

@Arf9999
Copy link

Arf9999 commented Nov 11, 2022 via email

@llrs
Copy link
Member

llrs commented Nov 11, 2022

@rbcavanaugh Yes, I am working on supporting API v2 but I had started by the streaming API which I thought would stop working last week.

The initial support for API v2 is already present in the devel branch but it is still not yet fully functional to be released (it doesn't have support for extensions and fields yet). If you want you can start a PR and I can help with it (you are not the first person to ask for it).

@AmeliaMN
Copy link

I got my twitter archive, but it doesn't seem to contain bookmarked tweets. I poked through the directory structure looking for anything that looked related, but couldn't find anything. If someone has figured out what file they are in, I'd love to know!

@llrs
Copy link
Member

llrs commented Nov 14, 2022

Mmh, yes I checked my own archive and it didn't even contain a reference to saved or bookmarked tweets. Sorry, I'll up this in the list of endpoints to provide support soon. However, the API requires a different authentication method for this endpoint, so existing code for API v2 doesn't work (I hoped it would).

@llrs
Copy link
Member

llrs commented Nov 20, 2022

I add here an app to retrieve all bookmarked tweets https://twitter-bookmarks-exporter.herokuapp.com/. It provides with a webpage with links to all the bookmarked tweets (and contents referenced there). Note it might take a long time to retrieve all the content.
Thanks @adriaaula for mentioning it.

@Lextuga007
Copy link

I've just used the app to get 289 links and it was really fast! Thanks for building and sharing @llrs

@deborahapthorp
Copy link

Thanks, but I couldn't get that app to work at all - is there a newer version?

@mpettis
Copy link

mpettis commented Dec 9, 2022

I get an Application Error on the herokuapp above, to confirm what I think @deborahapthorp is saying as well.

This was referenced Jan 14, 2023
@llrs
Copy link
Member

llrs commented Jan 28, 2023

Good news! I think I figured out the problem with the authentication method required for this (and others endpoints). It needs more testing and I need to understand more about it: if it will work with the current default token provided by rtweet (it doesn't seem to), and why it fails after some time using it (I think this is Twitter's fault as other tokens that did work also stopped working).
But in the devel branch (version 1.1.0.9002) there is a function to retrieve them! Hopefully next release (If I'm lucky next month) you will be able to download them.

However, the endpoint only returns the "Allows you to get an authenticated user's 800 most recent bookmarked Tweets." So if we'll get all or not (while testing it seemed at one point like it could continue to the next page above the 800 tweets).

@llrs
Copy link
Member

llrs commented Feb 2, 2023

Given that Twitter won't be free to download bookmarks next week (See announcement: https://twitter.com/TwitterDev/status/1621026986784337922) I recommend to extract the downloads with the code as is:

devtools::install_github("ropensci/rtweet@devel")
library("rtweet")
client <- rtweet:::rtweet_client() # You'll need to provide the id and secret of your app.
client_as(client)
token_oa2 <- rtweet:::rtweet_oauth2() 
ub <- rtweet:::user_bookmarks("123456789", parse = FALSE, n = Inf, token = token_oa2)
saveRDS(ub, "my_bookmarks.RDS")

The authentication mechanism might not work, if it does, it will be for only 2 hours.
I'm reconsidering the future of the package and my investment in it, but I'll keep monitoring and post more as the changes develop.

@adriaaula
Copy link

Thanks a ton for the code snippet Lluis!
It's disappointing to say the least, and it adds up more pressure to go somewhere else, let's hope I have enough pressure to go now haha

@Lextuga007
Copy link

Yes, echo that, thanks for the tip off that it's going to charge soon. Much appreciated!

@bassamsdata
Copy link

bassamsdata commented Feb 3, 2023

The authentication mechanism might not work, if it does, it will be for only 2 hours.
I'm reconsidering the future of the package and my investment in it, but I'll keep monitoring and post more as the changes develop.

Thank you so much for all the support and effort you put in this package.

unfortunately, The message always appears when I try to do anything, the error message appears when token_oa2 <- rtweet:::rtweet_oauth2() even though I provided the id and secret.

is there a way to export the bookmarks 🫣. note: I used to authenticate using the default in the browser.

Screen Shot 2023-02-03 at 11 13 17 AM

Screen Shot 2023-02-03 at 11 15 53 AM

Screen Shot 2023-02-03 at 11 16 01 AM

@mpettis
Copy link

mpettis commented Feb 3, 2023

@llrs I completely understand your question to further support of this package. I appreciate your work to this point, and will just say my use case is to just extract meaningful history from Twitter before I stop using it altogether. Thanks for the work I've used!

@bassamsdata
Copy link

unfortunately, The message always appears when I try to do anything, the error message appears when token_oa2 <- rtweet:::rtweet_oauth2() even though I provided the id and secret.

I just want to update on my comment that after removing the s from https://127.0.0.1:1410/ I wan able to authenticate yet another problem appeared when doing ub <- rtweet:::user_bookmarks("123456789", parse = FALSE, n = Inf, token = token_oa2)
Screen Shot 2023-02-03 at 11 34 47 AM

I have the last verion of httr2 and the last version of rtweet@devel.

Thanks a lot

@llrs
Copy link
Member

llrs commented Feb 3, 2023

@bassamsdata Did you replace 123456789 by your own Twitter id?

@bassamsdata
Copy link

@bassamsdata Did you replace 123456789 by your own Twitter id?

yea absolutely :)

@llrs
Copy link
Member

llrs commented Feb 3, 2023

I'll need more information to try to help you. What is the token_oa2 output? What is the client output? What did you try?

@bassamsdata
Copy link

Thanks for you help, I'm just trying to download my book marks. they are around 500 to 600.

token_oa2 output:
Screen Shot 2023-02-03 at 12 17 16 PM

rtweet:::rtweet_client() output with client id and client secret
Screen Shot 2023-02-03 at 12 18 22 PM

no output for this rtweet:::client_as(client)

output for this token_oa2 <- rtweet:::rtweet_oauth2()
Screen Shot 2023-02-03 at 12 21 23 PM

so I added client manually token_oa2 <- rtweet:::rtweet_oauth2(client = client)
and the output is to open the browser and authorize. I did authorize,
Screen Shot 2023-02-03 at 12 25 51 PM

and checked the app inside the twitter settings.
image

then when I try to download my bookmarks, it shows this error:
Screen Shot 2023-02-03 at 12 27 22 PM

just to note: if i did something like this useRs <- search_users("#tidytuesday", n = 100) it works.

@llrs
Copy link
Member

llrs commented Feb 4, 2023

@bassamsdata Please next time post text instead of images, it is easier to search and copy to the terminal.
It would be helpful to know the id of your client (and without the secret I cannot do anything). It would help me verify if you used the default client or not. If you used the default client it won't work.
The search_users used a different token for the requests. It wasn't used to make the requests, you should have used search_users("#tidytuesday", n = 100, token = token_oa2). The OAuth2 token is only valid in some endpoints of the the API v2 not in the v1.

@bassamsdata
Copy link

Please next time post text instead of images, it is easier to search and copy to the terminal.

My bad, sorry.

It would be helpful to know the id of your client

client <- rtweet:::rtweet_client(client_id = "dWJSZXljQ2NSQkNlNFFlc3lNZm86MTpjaQ",
                                 client_secret = )
<httr2_oauth_client>
name: rtweet
id: dWJSZXljQ2NSQkNlNFFlc3lNZm86MTpjaQ
secret: <REDACTED>
token_url: https://api.twitter.com/2/oauth2/token
auth: oauth_client_req_auth_header

If you used the default client it won't work.

I used the twitter provided client.

The search_users used a different token for the requests

> search_users("#tidytuesday", n = 100, token = token_oa2)
Error in `check_token()`:
! `token` is not a valid access token
Run `rlang::last_error()` to see where the error occurred.

the output of client and token_oa2

> client
<httr2_oauth_client>
name: rtweet
id: dWJSZXljQ2NSQkNlNFFlc3lNZm86MTpjaQ
secret: <REDACTED>
token_url: https://api.twitter.com/2/oauth2/token
auth: oauth_client_req_auth_header

> token_oa2
<httr2_token>
token_type: bearer
access_token: <REDACTED>
expires_at: 2023-02-04 12:59:07
refresh_token: <REDACTED>
scope: mute.write tweet.moderate.write block.read follows.read offline.access list.write bookmark.read list.read tweet.write space.read
block.write like.write like.read users.read tweet.read bookmark.write mute.read follows.write

here is the output of the user_bookmarks

> ub <- rtweet:::user_bookmarks("bassamstreet", parse = FALSE, n = Inf, token = token_oa2)
Error in `resp_abort()`:
! HTTP 401 Unauthorized.
Run `rlang::last_error()` to see where the error occurred.

@llrs
Copy link
Member

llrs commented Feb 6, 2023

I haven't heard complains from any other users (after last update of the sample code), I don't know for sure what might be the cause. It could be that your app is not authorized for API v2 and you might need to refresh the authorization or select a different type of APP in the developer.twitter.com menu, but using http://127.0.0.1:1410/ for confirming the app is fixed in rtweet code.

@bassamsdata
Copy link

I haven't heard complains from any other users (after last update of the sample code), I don't know for sure what might be the cause. It could be that your app is not authorized for API v2 and you might need to refresh the authorization or select a different type of APP in the developer.twitter.com menu, but using http://127.0.0.1:1410/ for confirming the app is fixed in rtweet code.

Thank you so much for your efforts to help me here, I really appreciated. It's probably an issue with my API. Thanks again

@llrs
Copy link
Member

llrs commented Feb 25, 2023

@bassamsdata Rechecking your code, I realize now that you were using you twitter name, not your id with numbers. I've added a check to detect those kind of errors.

I'm closing the issue now, as I've made user_bookmarks to be exported (for next release).

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("123456789", 
                     expansion = NA, fields = NA, # To export everything: alt text, images, urls, ...
                     parse = FALSE, n = Inf, token = token_oa2)
saveRDS(ub, "my_bookmarks.RDS")

@llrs llrs closed this as completed Feb 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests