With little experience in API programming, I am looking for a way to send a DELETE or POST request using the Twitter API v2.0 with the httr package in R. I usually use the academictwitteR package to interact with the API, but the package uses a bearer token authentication that seems to me to not be adequate for write privileges (required by DELETE and POST). Therefore, it seemed that the first step is setting up the OAuth 1.0a authentication credintials as described here. I downloaded and stored the four variables (oauth_token
; oauth_token_secret
; oauth_consumer_key
; oauth_consumer_secret
) from the app I created, but then I am stuck as to how to set up the request with httr
.
I can’t provide an example since I could not figure out the code, I hope you understand. Any help is much appreciated!
2
Answers
I looked at the curl examples for DELETE and POST requests you provided. They are rewrotten in R below. You need to replace the
$OAUTH_SIGNATURE
though. Please let me know if it works for you as I cannot check the code as I do not have a Twitter account nor do I have the OAuth token.Not sure about your specific requirements and what you tried before.
Would it be a solution to just use the
rtweet
package?It is quite handy and offers quite a lot of functions to interact with the twitter api(also posting and deleting tweets possible)
E.g.
To get you post ID to delete it, you can get maybe use
get_my_timeline
. This should give your posts with ids.See here in the vignette for a short intro about functions.
Of course you also need an access token first.
They have a very good explanation page on how to do this. Also a FAQ for problems. The explanation is rather long and probably too specific to go through in detail here. But would be interesting to know if it works for you.
Further things:
So try this:
Update
I just saw, on the very latest version in github they completely changed their methods and
create_token
is now depreciated.Here is the new way to do it: documentation
So seems you habe to use
rtweet_bot()
now.The rest of the code I posted should stay the same.
In general it seems there are 3 ways of authenticating now: